pratikshahse
asked on
How to get a specific value from a string
I have a string value of
string test = "99999\tAAAAAA\tOH\tX1 \tCentral\t754"
"99999\BBBB\tOH\tX1 \tCentral\t1234"
"99999\tfasdfjhsjf\tWV\tX1 \tCentral\t12345"
for int code , I want the value after the last "\t" from the above string values. How do I do that?
string test = "99999\tAAAAAA\tOH\tX1 \tCentral\t754"
"99999\BBBB\tOH\tX1 \tCentral\t1234"
"99999\tfasdfjhsjf\tWV\tX1
for int code , I want the value after the last "\t" from the above string values. How do I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi pratikshahse;
This will do it.
// Test Data
string test = @"99999\tAAAAAA\tOH\tX1 \tCentral\t75499999\BBBB\t OH\tX1 \tCentral\t123499999\tfasd fjhsjf\tWV \tX1 \tCentral\t12345";
// The needed data
string data = test.Substring(test.LastIn dexOf("\\" ) + 1);
Fernando
This will do it.
// Test Data
string test = @"99999\tAAAAAA\tOH\tX1 \tCentral\t75499999\BBBB\t
// The needed data
string data = test.Substring(test.LastIn
Fernando
This will pick out the digits between the last \t and the end of the string, and convert it to an integer:
Match match = Regex.Match(test, @"\t(\d+)$");
string digits = match.Groups[0].Captures[0].Value;
int value = int.Parse(digits);
int index = test.LastIndexOf("\t");
int code = 0;
if (index > -1)
code = int.Parse(test.Substring(i
Jim