|
-
Apr 20th, 2003, 10:28 AM
#1
Thread Starter
Registered User
How to cut a string? [Resolved]
I have a string of characters.
Eg. "Microsoft Visual Basic .NET"
Is there anyway or pre-defined function to cut the string into smaller groups, that will contain only a particular characters of the string?
Eg: After cutting, it becomes
"Microsoft" or
"Visual" or
"Basic" or
".NET"
Last edited by albertlse; Aug 21st, 2003 at 08:35 PM.
-
Apr 20th, 2003, 12:44 PM
#2
Frenzied Member
One easy way would be using Split.
VB Code:
Dim str as String="Microsoft Visual Basic .NET"
Dim SPstr() as String=str.Split(" ")
Split is more flexible than just splitting by a charachter.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 20th, 2003, 12:47 PM
#3
PowerPoster
Easy:
VB Code:
Dim myString As String
Dim myArrayOfStrings() As String
Dim i As Integer
myString = "Microsoft Visual Basic .NET"
myArrayOfStrings = myString.Split(" ")
For i = 0 To myArrayOfStrings.GetUpperBound(0)
MessageBox.Show(myArrayOfStrings(i).ToString())
Next
-
Apr 20th, 2003, 12:57 PM
#4
Sleep mode
You may have this as third option ! Use StringBuilder as follow :
VB Code:
Dim Strbuilder As New System.Text.StringBuilder()
-
Apr 20th, 2003, 01:30 PM
#5
PowerPoster
Originally posted by Pirate
You may have this as third option ! Use StringBuilder as follow :
VB Code:
Dim Strbuilder As New System.Text.StringBuilder()
That isn't what he was asking for though...
-
Apr 20th, 2003, 02:38 PM
#6
Sleep mode
Originally posted by hellswraith
That isn't what he was asking for though...
Well , if you read more about StringBuilder , you will know how much efficient it is . anyways I came up with another way though .
VB Code:
Dim b As System.Text.RegularExpressions.Regex
-
Apr 20th, 2003, 03:02 PM
#7
Frenzied Member
Please dont confuse the guy with Regex. Lets try with simpler ones.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 20th, 2003, 03:12 PM
#8
Sleep mode
Originally posted by Lunatic3
Please dont confuse the guy with Regex. Lets try with simpler ones.
hehe , he's not even responding . We just try to give him as much possible ways since .NET offer them apparently .
-
Apr 20th, 2003, 05:56 PM
#9
PowerPoster
What I am trying to say is that the code you give:
Dim Strbuilder As New System.Text.StringBuilder()
or
Dim b As System.Text.RegularExpressions.Regex
doesn't show him how to split a string. As a matter of fact it was confusing to me and I know what they are. It didn't help him is what I was saying. The full code on how to use them would be better, not just a declaration statement.
The stringbuilder class wouldn't be more efficient for this case. The stringbuilder class would be more efficient if you were building strings because it it allocates more memory when it needs it, and doesn't create a whole new address space in memory and copy the contents over to it when you add text to it.
When your splitting a string up, there is no way to get around of producing new strings in memory if you want them assigned to variables (or an array). Whether you do it with the string class, stringbuilder class, or through regular expressions, your code will still have to allocate new string variables in memory if your going to assign them to new variables.
-
Apr 20th, 2003, 06:09 PM
#10
Sleep mode
Originally posted by hellswraith
The stringbuilder class wouldn't be more efficient for this case. The stringbuilder class would be more efficient if you were building strings because it it allocates more memory when it needs it, and doesn't create a whole new address space in memory and copy the contents over to it when you add text to it.
When your splitting a string up, there is no way to get around of producing new strings in memory if you want them assigned to variables (or an array). Whether you do it with the string class, stringbuilder class, or through regular expressions, your code will still have to allocate new string variables in memory if your going to assign them to new variables.
I like this part ! exactly what I'w going to explain earlier .
about the way I posted the code hmm , I just wanted to give him another option although I'm sure he'll go for the first post though ..lol .
-
Apr 21st, 2003, 10:38 AM
#11
Thread Starter
Registered User
I can SPLIT the string now. Thank you.
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
|