Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c# string getting certain characters

Posted on 2014-01-04
3
Medium Priority
?
357 Views
Last Modified: 2014-01-12
Hi,

I have a string that gets displayed like so

ID: 223 Client Name: test

What I want to do is get the whole ID value

please help

Thanks

R8vI
0
Comment
Question by:R8VI
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 39756531
considering your other question:
http://www.experts-exchange.com/Programming/Languages/.NET/Q_28330657.html#a39756517

if you do apply that div technique to hide, you can quite easily do it with html or xml parser.
in any case, you can do it with a regular expression

using System.Text.RegularExpressions;

Match match = Regex.Match(your_string, @"ID:\s*([0-9]+)\s");

Open in new window

and the match object should give you the properties to get the ID value then.
0
 
LVL 40
ID: 39758069
You can use the Substring method of the string class.

If the ID is always 3 characters, then use the following:

yourString.Substring(4, 3);

Otherwise:

yourString.Substring(4,yourString.IndexOf(' ',4)-4);
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 39760506
Hi,

I am confused for your question for how to answer it in which context.

Can you elaborate what you are trying to do and why? It will get you best answer for your question.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question