Hello ,
I have to cut a String
the substring method its good but it pass an index as integer
i have an example like this
visual | basic
how can i get f
First String :visual (from first to | )
second String :basic (from | to last )
Thanks !
Printable View
Hello ,
I have to cut a String
the substring method its good but it pass an index as integer
i have an example like this
visual | basic
how can i get f
First String :visual (from first to | )
second String :basic (from | to last )
Thanks !
First = MyString.Substring(0, MyString.IndexOf("|")
Second = MyString.Substring(MyString.IndexOf("|"), MyString.Length - 1)
http://msdn.microsoft.com/en-us/libr...rs(VS.80).aspx
Thanks m8
The first one Working but i got an exception on Second one
i dont know why ??
Use the first method (string.split) and this function returns a string array. You just read the appropriate element in the array to pull out what you need.
Code:Dim parts as string() = mystring.split("|"c)
If parts.Length > 1 Then
first = parts(0)
second = parts(1)
End If
Well the errors are very explanatory in .Net. The error should tell you what's wrong then you can look at the documentation I sent you which will show you the way...Quote:
Originally Posted by killer7k
I'll give you a hint. The second parameter of the Substring method is the length of characters to grab. In my example I'm passing how long the entire string is. So a little math jiggering will get you fixed.
Quote:
Originally Posted by kasracer
i cant find an explanation for it at last if i am not adding - 1
i cant explan it it's length problem use it a lot havent had this problem before
try it & you will see !
@stanav
Thanks m8 Working !
hey killer what are you trying to do? Are you trying to remove the | or are you trying to make seperate strings of visual | basic? If the latter see Stanav post.
Both
Code:Dim testString As String = "Visual | Basic | is | easy"
Dim foo() As String = testString.Split("|"c)
Debug.WriteLine("'Debug Output")
For x As Integer = 0 To foo.Length - 1
Debug.WriteLine("'" & foo(x))
Next
testString = testString.Replace("|", "")
Debug.WriteLine("'" & testString)
Stop
'Debug Output
'Visual
' Basic
' is
' easy
'Visual Basic is easy
Quote:
Originally Posted by dbasnett
I was making it separate
Working as Stanav PostCode:dom strs as String =Textbox1.text
dim s as String =strs.split("|")
dim s1,s2 as String
if s.length > 1 then
s1=s(0)
s2=s(1).TrimStart(" ")
end if
Thanks !