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.

OPK
  • 4,120
  • 6
  • 36
  • 66

2 Answers2

2

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

noRequestString = myString.Substring(myString.IndexOf("AS") + 3);
juharr
  • 31,741
  • 4
  • 58
  • 93
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
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122