How to strip off ','?

techques
techques used Ask the Experts™
on
Hi

I have a string input:

1926,1926,1926

But, I just need the string number before ','

How should I wirte C# code to get 1926 only?

as the number will be growing, it cannot use substring(0,4) to get it

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
02.{
03.    string t = "1926,1926,1926";
04.    
05.    this.Text = t.Substring(0, t.IndexOf(",") - 1);
06.}

Commented:
Pls note that the previous code only return the first occur before the "," = 1926

This code returns all the numbers separated in collection of string, which can be accessed by using index of the string
string t = "1926,1926,1926";
string[] objStrings = null;

05.    obj = t.Split(",");

obj now contains all the numbers before the commas

Author

Commented:
yes, it is what i need, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial