I need to search a large string for a particular substring. The substring will start with Testing=
but everything within the double quotes could be different because its a user login.
So examples of the substring I need are
Testing="network\smithj"
or
Testing="network\rodgersm"
Do my requirements make sense? How can I do this in C#?
This is a great application of a regular expression.
"Testing=\"[^\"]*\""
You will use it like so:
Regex reg = new Regex("Testing=\"[^\"]*\"");
string login = reg.Match(yourInputString).Groups[0].Value;
The above works with your two given test cases.
Wikipedia has a great article on Regular Expressions if you are not familiar with them. And if you search google you can find a wealth of info on how to use Regular Expressions in C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With