regex - Removing 3 specific characters, if present from the start of a string VB.net -
i have situation need remove prefix string, if exists.
dim str string = "samvariable" needs converted variable
easy, trimstart
str = str.trimstart("s"c, "a"c, "m"c) except...
the string might not start "sam"
example:
dim str string = "saledetails" this become aledetails
which wrong, how replace
str = str.replace('sam','') brilliant! now:
example 1:
dim str string = "samvariable" str = str.replace('sam','') str = "variable" example 2:
dim str string = "saledetails" str = str.replace('sam','') str = "saledetails" (unaffected) but....
what if:
dim str string = "resample" str = str.replace('sam','') str = "reple" this wrong again!
so, question is:
how remove "sam" beginning of string only?
i had expected trimstart("sam") work, doesn't
if str.startswith("sam") str = str.substring(3) end if not one-liner, easy follow.
Comments
Post a Comment