Reputation: 11
I have a string array for Abc\r\n123PQR\r\n456
which i got from a container and I want only "ABC"
and "PQR
"using webdriver. How to get it ?
I have used Split("\r\n")
but its only returning 2 strings "ABC"
and 123PQR\r\n456
Any suggestions? Language is C# using webdriver.
Upvotes: 1
Views: 154
Reputation: 1353
Edit, according to test cases proposed:
Regex reg = new Regex(@"([A-Za-z].*)", RegexOptions.Singleline);
// Split the string on line breaks, removing parts consisted of only numbers
// ... The return value from Split is a string array.
string[] lines = Regex.Split(Regex.Replace(value, @"(?<=\n)(.[\d]*)(?=\r)|(?<=\n)(.[\d]*)(?=$)|(?<=^)(.[\d]*)(?=\r)", string.Empty), "\r\n");
//Removing empty spaces with Linq
lines = lines.Where(x => !string.IsNullOrEmpty(x)).ToArray();
for (int i = 0; i < lines.Count(); i++)
{
Match m = reg.Match(lines[i]);
if (m.Success)
{
lines[i] = m.Value;
}
Console.WriteLine(lines[i]);
}
}
Upvotes: 0
Reputation: 6968
To get words in sequence try this
string sequence = "Abc\r\n123PQR\r\n456";
string[] itemsArray = sequence.Split(new char[] { '\r', '\n' },
StringSplitOptions.RemoveEmptyEntries);
List<string> itemsList = new List<string>(itemsArray);
List<string> itemsListFind = itemsList.FindAll(
delegate(string item)
{
return
item.ToUpper().Contains("ABC") ||
item.ToUpper().Contains("PQR");
});
string[] result = itemsListFind.ToArray();
The result is:
{string[2]}
[0]: "Abc"
[1]: "123PQR"
Is it?
Upvotes: 1