Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How do I rightpad a string with spaces in script?
PostPosted: December 16th, 2005, 7:13 am 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
Hello,

I can't figure this out. I want to right pad a string with spaces so that I can line up some columns in a listbox.

I can't seem to find any string functions that do this and I'm a bit stumped.

Can it be done? Has anyone got any ideas?

Thanks,

Melanie :?

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


Top
 Profile  
 
 Post subject: This seems to be working
PostPosted: December 16th, 2005, 8:32 am 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
I include in case it's useful for others:

function rightPadStrings(column, len)
{
var numspaces = len - (String.length(column))

for (i=1; i <= numspaces; i++)
{
column = column + " "
}
return column;
}


Use like this:

var rightpaddedempname = rightPadStrings(string, 30);

Cheers,

Melanie :D

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


Top
 Profile  
 
 Post subject: Confused
PostPosted: December 16th, 2005, 10:05 am 
Offline

Joined: January 10th, 2005, 11:08 am
Posts: 63
Location: Birmingham, United Kingdom
Opus: All between ver Pro XE 4.5 and Ver 9.62
OS: Windows XP Pro SP3
System: Intel Core2 Duo 2.67Ghz, Matrox Millennium G550 dual head graphics card
I am still fairly new to this scripting lark and I have recreated your script in a blank production but cannot seem to figure out what it is doing. I can see it measures the string and then loops according to the result, adding a space as it goes but I cannot seem to get it to do anything to a string.
Would it take too much time to post a downloadable working example please?

Can you also explain the 'return' function, the script editor recognises it as a keyword but I cannot find any mention of it in the help file.
Thanks very much,
Andy Thompson.


Top
 Profile Visit website  
 
 Post subject: Here is the simplest example I can create
PostPosted: December 17th, 2005, 5:21 am 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
Hi Andy,

I've had a go at this and come up with the following (attached).

The string at the top of the page is recreated when you press Button 3 (labelled "rightpad with spaces") and strings the four input text fields together rightpadding each with spaces.

This example doesn't have any purpose because I wanted to take the database stuff out to simplify the example. But in my publication I'm using the rightpad to create columns in a listbox where each row is a number of columns from the database. To get each column to line up in the listbox I rightpad each before stringing it into the listbox.

Hope this helps and you find a use for it!

Best wishes,

Melanie :)

PS - return - hummmm..... it returns a variable from a function..... In this example it returns the value of column..... so that it can be assigned to another variable.

I know I haven't explained this properly - I'm not a programmer myself and often don't have the jargon right. Perhaps someone else with a better understanding could help out????


You do not have the required permissions to view the files attached to this post.

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Majestic-12 [Bot] and 49 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