Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 4:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Delete white spaces at end
PostPosted: November 3rd, 2014, 11:20 pm 
Offline

Joined: December 14th, 2004, 5:08 pm
Posts: 55
Location: Holland
Opus: version 8.0
OS: XP, Vista, Windows7, Windows8
System: Intel Corei7-2600 CPU 3.400GHz
Hi There,

In javascript (1.8.5 I thought ECMA-262) you can use the trim() method removes whitespace from both sides of a string.

var str = " Hello World! ";
alert(str.trim());

For browsers that do not support the trim() method, you can remove whitespaces from both sides of a string with a regular expression:

function myTrim(x) {
return x.replace(/^\s+|\s+$/gm,'');
}

function myFunction() {
var str = myTrim(" Hello World! ");
alert(str);
}

Were "\s" removes the whitespaces. Is there a line of script in Opus8 or 9 who do the same?

Thanks in advance for any help...


For this message ivisionar has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Delete white spaces at end
PostPosted: November 4th, 2014, 10:52 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
ECMA-262 is the standardisation used for JavaScript. Different versions of JavaScript are standardised in different editions of ECMAScript. Currently we're on ECMAScript 5.1 but work is under way on ECMAScript 6 - which I think is due next year?

OpusScript is based on the ECMA standardisation but one of the first editions and this makes it roughly equivalent to JavaScript 1.1 or 1.2. This means that as well as all the all the script functions in the Opus manual, you'll find JavaScript at that level may work as well for Opus Professional publications up to and including v8.

Opus Professional v9.5 includes a different publication type - HTML5. Because this is actual JavaScript, the version available in the published publication depends on the browser you use rather than OpusScript itself. Of course any work in the Opus IDE or standard (exe / plexus) publications still only have access to the OpusScript level.


As you don't have access to trim or regexp, you'll have to create a loop and read through the string checking the characters values and then extracting the part you want. Something like this might work:

Code:
str = trim("        hello world!           ");

function trim(tmpStr){
for (start=0;tmpStr.charCodeAt(start)=="32" || tmpStr.charCodeAt(start)=="9";start++);
for (end=tmpStr.length-1;tmpStr.charCodeAt(end)=="32"  || tmpStr.charCodeAt(end)=="9";end--);
return tmpStr.substring(start,end+1);
}


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Delete white spaces at end
PostPosted: November 4th, 2014, 11:35 pm 
Offline

Joined: December 14th, 2004, 5:08 pm
Posts: 55
Location: Holland
Opus: version 8.0
OS: XP, Vista, Windows7, Windows8
System: Intel Corei7-2600 CPU 3.400GHz
Super,
Thank you for the quick comment & reaction on this mackavi!

regards


For this message ivisionar has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group