✅ how do i trim this string
i have this long string for e.g string word = "iahdsoihdaiiadi1124I ID:whatever sidaohiow12" ; is it possible to get only word that comes after Id: .
C#
6 Replies
another way would be
whats supposed to be in them 2 dots
this got me every word that comes after id , i need only the word after id:
Nothing goes "in them 2 dots", those 2 dots are actually part of the code, they are how you specify a range in C#
Specifically
str[idStartIndex..spaceIndex]
gives you the substring from idStartIndex
(inclusive) to spaceIndex
(exclusive)Yeah, your regex is almost correct.
.*
will match everything after ID:
. You could add a space after the capture group and then do .*?
instead
Depending on the characters that can be in that id, you could also use ([\w\d]+)
instead of (.*?)
. This way you don't need to match the space afterwardsWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.