Mirage
Mirage

Reputation: 45

Cutting a string Until a particular character occurs

whats the code to cut or trim a string until a particular character is hit.

for example,

dim TestString as String = "REG - REGULAR"

output of this string after cutting should be,

"REG" 

The code should be able to cut the string until it reaches this character "-".

It should also remove the white spaces. whats the code for doing this task.

I am using vb.net.

Thank You

Upvotes: 0

Views: 16547

Answers (1)

Tilak
Tilak

Reputation: 30698

You can use String.Substring

TestString = TestString.Substring(0,TestString.IndexOf('-')).Trim()

Upvotes: 3

Related Questions