Link to home
Start Free TrialLog in
Avatar of Sam OZ
Sam OZFlag for Australia

asked on

Split numeric and non numeric in a string

I have a vb.net string for RevNo
I need a function that splits the numeric and alpha

For example  1A should be split as  1   A  ( split as Major and minor)
                       10A should be             10  A
Avatar of Dorababu M
Dorababu M
Flag of India image

Try this code

Dim input As String = "1A"
  Dim characters As List(Of Char) = New List(Of Char)()
  Dim numbers As List(Of Char) = New List(Of Char)()
  For Each c As Char In input
     If (Char.IsNumber(c)) Then
        numbers.Add(c)
     ElseIf (Char.IsLetter(c)) Then
        characters.Add(c)
     End If
  Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim revno = "10A"
Dim numbers = New String(revno.Where(Function(x) Char.IsDigit(x)).ToArray)
Dim chars = New String(revno.Where(Function(x) Char.IsLetter(x)).ToArray)
MsgBox(numbers & " => " & chars)

Open in new window