Reputation: 1897
I'm trying to figure out how I can remove only the slashes (forward and backward) that occur at the beginning of the string below, up until the first letter or number. I don't want to remove any slashes in the middle of the string.
string: "\//hello\how\are/you"
looking for result like this: "hello\how\are/you"
Thanks! Jason
Upvotes: 1
Views: 105
Reputation: 39700
string = string.TrimStart('\\', '/');
As an added bonus, you need not use a regex for this purpose.
Upvotes: 2
Reputation: 89639
You can use this pattern:
@"^[/\\]+"
It is a very basic pattern:
^
means start of the string
[/\\]
is a character class that contains /
and \
(note that you must escape the backslash to not escape the closing square bracket)
Upvotes: 4