0

I have some string variables with combinations of numbers and characters. like this:

A12452

BCD23

ESK56003

Using vbscript I want to get the characters and not the numbersfrom these strings. So I should get the following results.

A

BCD

ESK

note: im on VB6 right now.

Community
  • 1
  • 1
David Peterson
  • 552
  • 14
  • 31
  • 2
    This question is very confusing. Which programming language are you using? VB 6, VBScript, or VBA? Do you need a solution that will work with *all* of them, or just one of them? If you want to make this work in VBScript, why does it matter that you sometimes also use VB 6? It's especially difficult to tell, since you've used all of the tags! – Cody Gray - on strike May 11 '13 at 07:31
  • 2
    Related question: http://stackoverflow.com/q/8589746/262403 – Ilya Kurnosov May 11 '13 at 08:05
  • 1
    Along with the link Ilya posted, you could easily figure out the solution from my answer to [this question](http://stackoverflow.com/questions/15401434/vb-6-listview-substring-index). I'm pretty certain these string manipulation functions are common to all dialects of VB. – Cody Gray - on strike May 11 '13 at 08:16

1 Answers1

2

VBA:

Dim i As Long
Dim k As Long

k = Len (MyString)
i = 1
Do Until (i > k) Or (IsNumeric (Mid$ (MyString, i, 1)))
    i = i + 1
Loop

Result = Left$ (MyString, i - 1)

Edit: I just noticed that there might be a bug in this code as Or is not short-circuit in VBA (i.e. the expression following Or is evaluated even if the first expression is true). Probably the correct way of writing the loop would be

Do
    If i > k Then Exit Do
    If IsNumeric (Mid$ (MyString, i, 1)) Then Exit Do
    i = i + 1
Loop
JohnB
  • 13,315
  • 4
  • 38
  • 65