say if I have a string 010451-09F2
How to I get left of - from the above string in vb.net
I want 010451
The left fu
Sorry not sure on the vb syntax, but the c# is
string mystring ="010451-09F2";
string whatIwant = mystring.Split('-')[0];
This helped
Dim str1 as string = me@test.com
Dim str As String
str = Strings.Left(str1, str1.LastIndexOf("@"))
Get the location of the dash first (or do it inline), and use that value for the left. This is old school VBA, but it'll be something like this:
Left(YourStringWithTheDash, InStr(YourStringWithTheDash)-1)
Dim str As String = "010451-09F2"
Dim leftPart As String = str.Split("-")(0)
Split gives you the left and right parts in a string array. Accessing the first element (index 0) gives you the left part.
dim s as String = "010451-09F2"
Console.WriteLine(s.Substring(0, s.IndexOf("-")))
Console.WriteLine(s.Split("-")(0))
Given:
Dim strOrig = "010451-09F2"
You can do any of the following:
Dim leftString = strOrig.Substring(0, strOrig.IndexOf("-"))
Or:
Dim leftString = strOrig.Split("-"c)(0) ' Take the first index in the array
Or:
Dim leftString = Left(strOrig, InStr(strOrig, "-"))
' Could also be: Mid(strOrig, 0, InStr(strOrig, "-"))