Cannot trim closed bracket from vb.net string -
i have issue trimming string in vb.net
dim bgcolor1 string = (foundrows(count).item(16).tostring()) 'this returns color [indigo] need indigo vb.net can read it. 'so used dim mychar() char = {"c", "o", "l", "r", "[", "]", " "} dim firstbgcolorbgcolor1 string = bgcolor1.trimstart(mychar) 'but ] still in string looks indigo]
any ideas on why cannot trim ]?
update
didn't see input "color [indigo]". not recommend trimstart()
& trimend()
you have variety of options choose from:
imports system imports system.text.regularexpressions public module module1 public sub main() dim color string = "color [indigo]" ' substring() & indexof() dim openbracket = color.indexof("[") + 1 dim closebracket = color.indexof("]") console.writeline(color.substring(openbracket, closebracket - openbracket)) ' replace() console.writeline(color.replace("color [", string.empty).replace("]", string.empty)) ' regex.replace() console.writeline(regex.replace(color, "color \[|\]", string.empty)) ' regex.match() console.writeline(regex.match(color, "\[(\w+)\]").groups(1)) end sub end module
results:
indigo indigo indigo indigo
Comments
Post a Comment