Solved

Extract text using regex

Posted on 2013-02-06
1
370 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

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

Suggested Solutions

Title # Comments Views Activity
PowerShell: Office 365:  How to pass multiple license options from user input? 2 52
Regarding swagger API 1 38
Data organization issue 7 39
Adjust the codes 3 37
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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