Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Some Simple Text Manipulation

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,49139
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Some Simple Text Manipulation
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Some Simple Text Manipulation - 7/7/2007 8:13:19 AM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Since I am forever running into instances where I need to pad a string, or strip off the last few or starting few characters of a string, or capping the first letter of a string, etc.  I wrote myself some mini-functions.
They aren't fancy by any means, but they can really make coding a bunch nicer/simpler.

      

      

      

      

      

< Message edited by DiGiTAL.SkReAM -- 7/9/2007 12:16:09 AM >


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
 
Revisions: 2 | Post #: 1
 
 RE: Some Simple Text Manipulation - 7/8/2007 8:27:48 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
Nice set of function.
Especialy useful to avoid errors.

However for...
'This function removes the number of characters on the left of the String
...I use ...
Mid(MyString, xNumber)

_____________________________

Fred

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 2
 
 RE: Some Simple Text Manipulation - 7/9/2007 12:14:57 AM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Heh, you know, it never even occured to me that you can use Mid() like that.
However, after testing, it seems to give the proper result for the function, it would have to be
Mid(string,xNumber + 1)

The function has been modified.
Thanks!


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to Fredledingue)
 
 
Post #: 3
 
 RE: Some Simple Text Manipulation - 7/11/2007 1:30:46 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi DiGiTAL.SkReAM,

nice/useful code! I use (more dangerous) functions like

Function PadL( vVal, sChar, nWidth )
PadL = Right( String( nWidth, sChar ) + CStr( vVal ), nWidth )
End Function

to achieve something similiar. One proposal: How about using
Space( iNumChar - Len(s1) ) instead of String(iNumChar - Len(s1)," ")?

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 4
 
 RE: Some Simple Text Manipulation - 7/11/2007 1:36:26 PM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Hi ehvbs,

Thanks for the kind words.  All of it is pretty simple code, but again, so useful.

As to your Space( iNumChar - Len(s1) ) instead of String(iNumChar - Len(s1)," ") question, I use the string method, because someone might want to modify the function to pad it with zeros, or some other character instead of just being able to use spaces.  With the string line, it is so easy to just modify it:
String(iNumChar - Len(s1)," ")
String(iNumChar - Len(s1),"0")
String(iNumChar - Len(s1),"~")
etc.

I guess I should have made a function that would let you pad a string with the string of your choice, said choice being passed ont he commandline, but... I didn't have a need for it right at the moment, and so didn't write it.  Heh heh.  It should still be easy enough for folks to modify the aformentioned line to accept an argument of a character.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Some Simple Text Manipulation - 7/13/2007 6:43:19 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
quote:

ORIGINAL: DiGiTAL.SkReAM

Heh, you know, it never even occured to me that you can use Mid() like that.
However, after testing, it seems to give the proper result for the function, it would have to be
Mid(string,xNumber + 1)

The function has been modified.
Thanks!



Because Mid is used generaly with two var's ex: Mid(text, 5, 10). If you obmit the second var, it returns everything until the end of the word. Cool.
And you are right, we must add +1.

quote:

I guess I should have made a function that would let you pad a string with the string of your choice, said choice being passed ont he commandline, but... I didn't have a need for it right at the moment

...and  because it will make a sub almost as complicated as the full code.  [just kidding]

_____________________________

Fred

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Some Simple Text Manipulation Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts