Which is the best way to skip characters before underscore _ in a string using c#?
eg:case 1 String contain _
string s="abc_defg"
I want to get defg to another string
case 2
some times string do not contain _ . at that time i need to get the all string
eg.
s="defg"
In both case i want get “defg” . Filtering only applied if there is an underscore in the string. How can i do that
using the ternary operator here is quite useless, better to write:
directly, using the fact that
Substringprobably is optimized for the case index == 0Is this what you want?
BUT someone has suggested using LINQ cannons, so
In .NET 4.0 there is a new
string.Concatmethod.(note that in general the LINQ way is slower and more complex to read)
I’ll add the ultrakill: the Regular Expressions!!! There is a school of thought that anything can be done with Regular Expressions OR jQuery! 🙂
I won’t even try to explain this beast to anyone, so don’t ask. It’s useless. (both the Regex and to ask 🙂 )