Parse a string to first /

I have a field with values like this:

XY/12345
ABC/mm1888

I want to get XY and ABC...anything before the first /. How can I do this ?
LVL 8
CamilliaAsked:
Who is Participating?
 
Padre_CorleoneConnect With a Mentor Commented:
Dim str as string = "XY/12345"
Str = str.split("/")(0)
0
 
Jared_SCommented:
You'll have to use a scripting language to isolate the section of the string you're after.

Here is a vb.net example...

Dim myString as string = <pass your string value to your variable>

Dim myNewString as string = myString.Substring(0,patindex("/.",myString) -1)
0
 
CamilliaAuthor Commented:
this is C# and the converted the first solution to C# but i get an error that split wants a "char" type field

string str = "XY/12345";
str = str.Split("/")[0];
0
 
CamilliaAuthor Commented:
my bad. first solution worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.