Click here to Skip to main content
11,803,861 members (78,594 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB string VB.NET
Dim strmystring as stirng = “record0030040acd035a856ab”
In this case I want to find 040 (but it could be 034 or 856)
Dim I as interger = strmystring.indexof(“040”)
Next ouput the substring
Dim strsubstring as string = strmystring.substring(i)
Now my stirng looks like “040acd035a856ab”
With this string how can I output the fallowing:

So I want the alphabets after 040, appreciate any ideas.
Posted 23-May-11 7:20am
Edited 23-May-11 7:24am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you know it only needs the next 4 characters...change your substring line to this:
Dim strsubstring as string = strmystring.substring(i,4)

The second parm on the substring function means you want to pull the next 4 characters.

--- oops...I didn't read your question well enough...

You'll need to pull the whole thing like you did before. I suppose then you could loop through the string and look for the first character that is could use the IsNumeric[^] function. Or you could figure out a way to do it with regular expressions.

Here are google results[^] for regular expressions. Here are CP Articles[^] for regular expressions. These should help you get started.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I have written it:
Module Module1
    Sub Main()
        Dim Str = "record0030040acd035a856ab"
        Dim I = Str.IndexOf("040")
        For a = I + 3 To Str.Length - 1
            Dim Chr = Str(a)
            If Char.IsLetter(Chr) Then
                Console.WriteLine("040" + Chr)
                Exit For
            End If
    End Sub
End Module
stopete82 at 23-May-11 13:36pm
Thanks this is what I was looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 450
1 CPallini 320
2 F-ES Sitecore 240
3 Sergey Alexandrovich Kryukov 234
4 CHill60 220
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 23 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100