Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
Hi all,
my string a="A0001".
How i get the value "0001"
 
Thanks in advance
Posted 25-Dec-12 2:05am
Comments
Krunal Rohit at 25-Dec-12 7:08am
   
be clear with your issue..
Manojit Mondal at 25-Dec-12 7:13am
   
i have a string a ="A0001". i want to cut "A" word.
Zoltán Zörgő at 25-Dec-12 7:13am
   
What about String.Substring?
string cuted=a.Substring(1);
Manojit Mondal at 25-Dec-12 7:15am
   
please be specific.
Zoltán Zörgő at 25-Dec-12 7:16am
   
Me? How to be more specific?
Manojit Mondal at 25-Dec-12 7:22am
   
sorry at 1st i did not see your example.
Manojit Mondal at 25-Dec-12 7:20am
   
thanks it works.......
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
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:
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;
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi , try next:
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();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

string a="A0001";
a = a.split('A')[0].ToString();
  Permalink  

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

  Print Answers RSS
0 Zoltán Zörgő 185
1 Sergey Alexandrovich Kryukov 160
2 Peter Leow 100
3 CPallini 70
4 Ramza360 51
0 Zoltán Zörgő 80
1 the other paul 23
2 Shmuel Zang 10
3 Aarti Meswania 5
4 Member 11389991 -2


Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 25 Dec 2012
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