|
-
Jan 5th, 2003, 03:33 AM
#1
Thread Starter
Addicted Member
Trimming question
Here's a quick string trimming question. I have the following strings:
-1 HELLO HELLO2
56 'TESTING YOU'
0 AGAIN
How do I trim out only the first number up until the space. Also, how do I trim out all of the text right after the first space?
Thanks!
-- Ethan --
VB6, VB.NET, C#, SQL, XML, ADO.NET, ASP.NET, HTML.
MCP & A+ Certified. Looking for a job in the Seattle, WA area.
-
Jan 6th, 2003, 02:34 AM
#2
Fanatic Member
Try this
VB Code:
Dim strList As String = "-1 HELLO HELLO2"
Dim words() As String
' Split text using space as separator
words = strList.Split(" ")
MessageBox.Show(words(0))
Or you could use try this one
VB Code:
Dim strList as string = ""-1 HELLO HELLO2"
MessageBox.Show(strList.Substring(0, strList.IndexOf(" ")))
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Jan 6th, 2003, 03:29 AM
#3
-
Jan 6th, 2003, 03:58 AM
#4
Fanatic Member
Thanks for your suggestion MrPolite. I tried the code below and it won't do what ethanwa is looking for.
VB Code:
Dim strList As String = "-1 HELLO HELLO2"
Dim words() As String
' Split text using space as separator
words = strList.Split(" ", 1)
MessageBox.Show(words(0))
--------------------------------------------------------------------------------
The above code will display "-1 HELLO HELLO2". So, it seems that the second parameter specifies the number of elements in the array.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Jan 10th, 2003, 09:23 PM
#5
Originally posted by Mr.No
Thanks for your suggestion MrPolite. I tried the code below and it won't do what ethanwa is looking for.
VB Code:
Dim strList As String = "-1 HELLO HELLO2"
Dim words() As String
' Split text using space as separator
words = strList.Split(" ", 1)
MessageBox.Show(words(0))
--------------------------------------------------------------------------------
The above code will display "-1 HELLO HELLO2". So, it seems that the second parameter specifies the number of elements in the array.
try passing "2" as the argument. when you pass "1" it means that the function will only return one element. 2 means it will try to split the string in only two parts. (it might not split it at all if there isnt a space in your string)
VB Code:
Dim strList As String = "-1 HELLO HELLO2"
Dim words() As String
' Split text using space as separator
words = strList.Split(" ", [b][size=4][color=red]2[/color][/size][/b])
MessageBox.Show(words(0))
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|