0

I have thousands of lines of string type data, and what I need is to extract the string after AS. For example this line:

CASE  END AS NoHearing,

What I want would be NoHearing,

This line:

 CASE 19083812 END AS NoRequset

What I need would be NoRequset

So far I have tried couple ways of doing it but no success. Can't use .split because AS is not Char type.

4
  • 3
    You can split by strings. msdn.microsoft.com/en-us/library/tabh47cf%28v=vs.110%29.aspx Commented Apr 27, 2015 at 17:40
  • Is it safe to assume that "AS" only appears once (and must happen, no rows without)? If not, what about "END AS"? Commented Apr 27, 2015 at 17:42
  • 1
    Split by the whitespace ' ' and take the .Last() result. Commented Apr 27, 2015 at 17:44
  • @Pierre-LucPineault Your method worked perfectly for me. Commented Apr 27, 2015 at 18:27

2 Answers 2

2

If this will be the only way that AS appears in the string:

noRequestString = myString.Substring(myString.IndexOf("AS") + 3);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @juharr - appreciate the correction as I get used to the UI.
0

Using Regex I extract all between the AS and a comma:

string data = @"
CASE  END AS NoHearing,
CASE 19083812 END AS NoRequset
";

var items = Regex.Matches(data, @"(?:AS\s+)(?<AsWhat>[^\s,]+)")
                 .OfType<Match>()
                 .Select (mt => mt.Groups["AsWhat"])
                 .ToList();


Console.WriteLine (string.Join(" ", items)); // NoHearing NoRequset

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.