Solved

Extract text using regex

Posted on 2013-02-06
1
367 Views
Last Modified: 2013-02-06
Hi

I have the following in a text file:

"username":"blah"

How could I use a regular expression to extract just "blah" using c#?

Thanks
0
Comment
Question by:zattz
1 Comment
 

Accepted Solution

by:
zattz earned 0 total points
ID: 38859772
public static string extractTo(string html)
        {
            string anchor = "\"username\":\"";
            int startIndex = html.IndexOf(anchor) + anchor.Length;
            int endIndex = html.IndexOf('"', startIndex);
            string txt = html.Substring(startIndex, endIndex - startIndex);
            return txt;
        }
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 35
InputLanguage 1 27
Example works but why do I need to click twice on button 4 43
Problem with SelectList in .NET MVC application 1 18
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 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