Example Below - "\r\n                     \r\n                         \r\n                         \r\n                       ...

How to extract only Numbers eliminating escape sequence?



Example Below -
"\r\n                    \r\n                        \r\n                        \r\n                            \r\n                            \r\n                                10\r\n                                \r\n            
                \r\n                                25\r\n   
                             \r\n                            \r\n                                50\r\n                                \r\n                            \r\n                                75\r\n                                \r\n                            \r\n                                100\r\n                                \r\n                            \r\n                        \r\n                        \r\n                        \r\n                        \r\n                    \r\n                "



var element = Driver.driver.FindElement(By.ClassName("ui-dropdown-items-wrapper")).GetAttribute("textContent");
List<string> s = new List<string>();
          
string[] stringSeparators = new string[] { "\r\n" };
string[] lines = element.Split(stringSeparators, StringSplitOptions.None);
foreach (string s1 in lines)
{
     if (s1.Trim() != "")
     {
         s.Add(s1.Trim());                
     }
}
foreach (string a in s1)
{
     Console.WriteLine(a);
}

StringSplitOptions.None
The option "StringSplitOptions.None" is the default, which means that if two of your specified delimiter are next to each other, you'll get an element in the array that contains an empty string.

String.Trim()
S1.Trim() - Removes all leading and trailing white-space characters from the current String object.

We can use this above logic to even split string on multiple character.




0 comments: