Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts

    How to separate character and number (VbScript)?


    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    41 8' 52" N -95 53' 31" W
    Thanked 0 Times in 0 Posts
    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.
    Last edited by whammy; 09-20-2002 at 01:08 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts