0

What I want to do is be able to remove a section of a string and use the remaining portion of it to add to a Combobox.

Dim randString As String = ""
textbox.text = "(Remove this) - Keep this"
randString = textbox.text.... ' Trim/Split the first portion off somehow?
combobox.items.add(randString)

' Result should look like " - Keep this"

I've tried Trim/Split without any luck. Could anyone point me in the right direction? Thanks.

  • Posted but misread the question, thinking you just intended to split by a single char. However your example seems to indicate you'd like to split at a string. Is there a particular character sequence you want to split at, like the space and dash? See this: http://stackoverflow.com/questions/1639189/vb-net-can-you-split-a-string-by-a-string – Daniel Langemann Aug 03 '16 at 18:38
  • I would just like to remove "(Remove this)" and keep " - keep this". – RockGuitarist1 Aug 03 '16 at 18:45
  • I updated my answer - is that more like what you're looking for? – Daniel Langemann Aug 03 '16 at 19:27

1 Answers1

2

If you just want to remove a portion of the string, you can use the Replace function:

randString = Replace(textbox.text, "(Remove this)", "")

You can put any string variable in as the second argument.