View Full Version : How to separate character and number (VbScript)?

09-13-2002, 12:15 PM

I have been using fucntions like instr(), split(), regexp()..etc for manipulating string, but now in difficulty fo separate character and number, please help, really no idea.

for example: I want to split amelia1 to amelia and 1 and after that change the "a" to Upper case (A) so become Amelia 1 (this is the titile name for my property.

09-20-2002, 02:06 AM
If you know for sure that the only numeric character(s) in the string is/are going to be at the end, you can use a RegEx for that too... in this one I'm assuming it's one or more numbers...

Function SplitIt(str)
If IsNull(str) Then str = ""
Dim siRegEx
Set siRegEx = New RegExp
siRegEx.Pattern = "^(\D+)(\d{1,})$"
SplitIt = siRegEx.Replace(str,"$1 $2"))
End Function

I haven't tested it, but that should split your string up the way you want. I'm sure you can figure out how to capitalize the first letter of Amelia. :)