Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Is there a way to extract a certain digit sub string from a string in vb.net or c#.net?

E.g- ABVDFGFHJXXXX is a substring that can appear anywhere in a string. There can be other substrings of same length but of different alphanumeric combination(say 97DBCHFJKXXXX) in the same string. Then how to extract those 13 digit long sub strings?

I want to get those 13 digit long substrings in some variable
like variable a=ABVDFGFHJXXXX and b=97DBCHFJKXXXX. Or may be I can use a loop.

In all I want to extract words of length 13 from a string, without knowing the string content.

Any help would be greatly appreciated!!
Posted
Updated 26-Aug-14 21:21pm
v4
Comments
Bernhard Hiller 27-Aug-14 2:17am    
"but of different combination" what does that mean? Can you provide some examples of valid data (and perhaps also of invalid data)?

From what I could understand of your question (Please correct if wrong).

Following should give out all the actual values based on a pattern from an input string.

C#
string input = "Your Input String ABVDFGFHJ1234.";
// Create Your Pattern ABVDFGFHJXXXX or similar
// I have assumed your pattern is 9 Alphabets followed by 4 digits
string pattern = @"([A-Z]{9}[0-9]{4})";

foreach (Match match in Regex.Matches(input, pattern))
{
    // say you wish to print those values
    Console.WriteLine(match.Value);
}
 
Share this answer
 
Comments
Kim Togo 27-Aug-14 4:07am    
My 5. I think you are have the correct solution. What I can understand for OP, is that he wants to extract information based on text and numbers in a specific appearance.
as Bernhard Hiller sayed, some more Info would be great!

but from that what i guessed, shouldn't a simple

VB
Dim myString As String = "ALSDJAHSLDJhp4uihapofjsfd"
myString = myString.Replace("ALSDJAHSLDJ", Nothing)

-> myString ->> hp4uihapofjsfd


just do your thing?
 
Share this answer
 
You can use this code

string strItem="123ABVDFGFHJXXXX";

string strNewValue=strItem.Replace("ABVDFGFHJXXXX","").Trim();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900