Sign in to follow this  
Followers 0
PerryRaptor

StringFormat() Question

4 posts in this topic

I've been torturing StringFormat() trying to come up with a way to make variables that have fewer than 25 characters pad spaces to the right. I need to have the variables 25 charaters in length before moving on to the next procedure.

Other ideas are welcome...

201.201.201.201 ; is less than 25 characters

www.autoitscript.com/forum/index.php ; is more than 25 characters; 11 too many

So that it will look like this if called via MsgBox Print >>>201.201.201.201 <<<

or this, >>>www.autoitscript.com/foru<<<

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've been torturing StringFormat() trying to come up with a way to make variables that have fewer than 25 characters pad spaces to the right. I need to have the variables 25 charaters in length before moving on to the next procedure.

Other ideas are welcome...

201.201.201.201 ; is less than 25 characters

www.autoitscript.com/forum/index.php ; is more than 25 characters; 11 too many

So that it will look like this if called via MsgBox Print >>>201.201.201.201 <<<

or this, >>>www.autoitscript.com/foru<<<

I would do it this way:

$YourVar = StringLeft($YourVar & "                       ",25)

:o

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$s_text = "201.201.201.201.11111111111122222222"

$s_text = StringFormat(">>>>%-25s<<<<",StringLeft($s_text,25))
MsgBox(0,"test",$s_text)


$s_text = "201.201.201.201"
$s_text = StringFormat(">>>>%-25s<<<<",StringLeft($s_text,25))
MsgBox(0,"test",$s_text)


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

the helpfile for StringFormat() wasn't making any sense to me...thanks folks!

This idea worked the best:

;Shorten the variable when too long
$s_text = "201.201.201.201.11111111111122222222"

$s_text = StringFormat(">>>>%-25s<<<<",StringLeft($s_text,25))
MsgBox(0,"test",$s_text)

;Lengthen the variable when too short
$s_text = "201.201.201.201"
$s_text = StringFormat(">>>>%-25s<<<<",StringLeft($s_text,25))
MsgBox(0,"test",$s_text)
Edited by PerryRaptor

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0