|
-
Sep 23rd, 2006, 05:09 PM
#1
Thread Starter
G&G Moderator
[RESOLVED] String split
Howdy all,
In VB6 I wrote a function to split a string by a character, which ignored quotes.
For example, the Split functions in VB6 and C# would split the following string:
He said, "Hello, my name is blahblah!", to everyone.
VB6 and C# will split this like so, using a comma as the split character:
1) He said
2) "Hello
3) my name is blahblah!"
4) to everyone.
What my function did was split it like so:
1) He said
2) "Hello, my name is blahblah!"
3) to everyone.
I'm having trouble porting it to C#. Obviously, it returned a string array, but in VB I had the comfort of using ReDim. Can anyone write me a function to split by character but ignore quotes? My brain just doesn't want to work today :/
Cheers for any help,
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 23rd, 2006, 08:24 PM
#2
Hyperactive Member
Re: String split
The String class has a Replace and Split function. Those will help you !
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Sep 23rd, 2006, 08:28 PM
#3
Re: String split
.NET 2.0 provides the Array.Resize method, which does for every .NET language what VB's ReDim Preserve did just for VB.
-
Sep 23rd, 2006, 08:35 PM
#4
Hyperactive Member
Re: String split
 Originally Posted by BramVandenbon
The String class has a Replace and Split function. Those will help you !
Yeah I just realized I didn't read your question good enough, sorry
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Sep 23rd, 2006, 11:22 PM
#5
Thread Starter
G&G Moderator
Re: String split
 Originally Posted by jmcilhinney
.NET 2.0 provides the Array.Resize method, which does for every .NET language what VB's ReDim Preserve did just for VB.
Hmm. I really should re-lookup most of the stuff. I haven't used .NET in a long long time..
Thanks for the help, I ended up just looping through and storing them in an ArrayList, then copying that to a string array.
I'll lookup that Resize stuff jmc...cheers.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 23rd, 2006, 11:31 PM
#6
Re: [RESOLVED] String split
Don't use ArrayLists in .NET 2.0. If you want a collection of String objects then use a StringCollection, which was available in .NET 1.x too, or a List(Of String). Only use an ArrayList on the rare occasion that you want to be able to store multiple, unrelated types in the same collection.
-
Sep 24th, 2006, 04:44 AM
#7
Thread Starter
G&G Moderator
Re: [RESOLVED] String split
 Originally Posted by jmcilhinney
Don't use ArrayLists in .NET 2.0. If you want a collection of String objects then use a StringCollection, which was available in .NET 1.x too, or a List(Of String). Only use an ArrayList on the rare occasion that you want to be able to store multiple, unrelated types in the same collection.
I am actually looking to store different types in there aswell, but thanks for the advice 
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
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
|