Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
my string a="A0001".
How i get the value "0001"

Thanks in advance
Posted
Comments
[no name] 25-Dec-12 7:08am    
be clear with your issue..
Manojit Mondal 25-Dec-12 7:13am    
i have a string a ="A0001". i want to cut "A" word.
Zoltán Zörgő 25-Dec-12 7:13am    
What about String.Substring?
string cuted=a.Substring(1);
Manojit Mondal 25-Dec-12 7:15am    
please be specific.
Zoltán Zörgő 25-Dec-12 7:16am    
Me? How to be more specific?

Exactly how you do this will depend on what your data format is like. If it is always "one character, followed by four numerics, then it is trivial:
C#
string inp = "A0001";
string alpha = inp.Substring(0,1);
string numeric = inp.Substring(1);
If on the other hand it is a variable length non-numeric at the front, then you would be better off using a Regex:
C#
string inp = "A0001";
Regex regex = new Regex(@"(?<Alpha>[^\d]*)(?<Numeric>\d+)");
Match m = regex.Match(inp);
string alpha = m.Groups["Alpha"].Value;
string numeric = m.Groups["Numeric"].Value;
 
Share this answer
 
v2
Hi , try next:
C#
string a="A0001";
char[] array=a.ToCharArray();
var accumulator=new StringBuilder();
foreac(c in array)
{
if(char.IsDigit(c))
accumulator.Append(c);
}
string result =accumulator.ToString();
 
Share this answer
 
C#
string a="A0001";
a = a.split('A')[0].ToString();
 
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