|
-
May 7th, 2008, 11:36 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Cut String !
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 !
-
May 7th, 2008, 11:49 AM
#2
Re: [2005] Cut String !
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
-
May 7th, 2008, 12:29 PM
#3
Thread Starter
Fanatic Member
Re: [2005] Cut String !
Thanks m8
The first one Working but i got an exception on Second one
i dont know why ??
-
May 7th, 2008, 12:35 PM
#4
Re: [2005] Cut String !
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
-
May 7th, 2008, 12:38 PM
#5
Re: [2005] Cut String !
 Originally Posted by killer7k
Thanks m8
The first one Working but i got an exception on Second one
i dont know why ??
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...
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.
-
May 7th, 2008, 12:46 PM
#6
Thread Starter
Fanatic Member
Re: [2005] Cut String !
 Originally Posted by kasracer
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...
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.
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 !
-
May 7th, 2008, 02:21 PM
#7
Re: [RESOLVED] [2005] Cut String !
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
-
May 7th, 2008, 02:27 PM
#8
Thread Starter
Fanatic Member
Re: [RESOLVED] [2005] Cut String !
 Originally Posted by dbasnett
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
I was making it separate
Code:
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
Working as Stanav Post
Thanks !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|