PC Review


Reply
Thread Tools Rate Thread

Creating a delimited string

 
 
Raterus
Guest
Posts: n/a
 
      12th Jul 2004
Very often while programming, I need to create a delimited string with various values.

value1;value2;value3

Here is the problem I run into, and this isn't that big of deal, I always work around it.
I either have to check to see if it is the first value I added, and not put the delimiter, which each subsequent value would be delimiter & value,
or
after I add all the values, I remove the delimiter from the end.

Either works fine, I was just wondering if there is a more efficient, easier to code, way I could be going about this.

I was looking at the string builder class, and I didn't see this ability, but if I could load all the values, then perform a tostring that would delimit them for me, that would work so much easier! Maybe there are some other objects out there that could do this, or even I could extend the StringBuilderClass

Anyone have any ideas?
--Michael
 
Reply With Quote
 
 
 
 
Chris Gallucci
Guest
Posts: n/a
 
      12th Jul 2004
String.Join(";", New String() { value1, value2, value3})

ChrisG


 
Reply With Quote
 
Patrick Steele [MVP]
Guest
Posts: n/a
 
      12th Jul 2004
In article <(E-Mail Removed)>, (E-Mail Removed)
says...
>
> Very often while programming, I need to create a delimited string with various values.
>
> value1;value2;value3
>
> Here is the problem I run into, and this isn't that big of deal, I always work around it.
> I either have to check to see if it is the first value I added, and not put the delimiter, which each subsequent value would be delimiter & value,
> or
> after I add all the values, I remove the delimiter from the end.
>
> Either works fine, I was just wondering if there is a more efficient, easier to code, way I could be going about this.
>
> I was looking at the string builder class, and I didn't see this ability, but if I could load all the values, then perform a tostring that would delimit them for me, that would work so much easier! Maybe there are some other objects out there that could do this, or even I could extend the StringBuilderClass
>
> Anyone have any ideas?


Look into the "Join" function.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
 
Reply With Quote
 
Tibby
Guest
Posts: n/a
 
      12th Jul 2004
You can store all the values in an array or arraylist, then use the
join function. One thing I do, is use the StringBuilder, and add the
delimeter to each one, then right before I write out the string, I
just strip the last delimeter off. This solution is great for large
amounts of data, but, for small amounts, the array solution may work
just fine. One other thing to look into is writing out a file with
ADO, defining your delimters.
Basically, there's more than one option, depending on what you need
and how much data you need to store in memory.

HTH,
Tibby
On Mon, 12 Jul 2004 10:26:12 -0400, "Raterus" <(E-Mail Removed)>
wrote:

>Very often while programming, I need to create a delimited string with various values.
>
>value1;value2;value3
>
>Here is the problem I run into, and this isn't that big of deal, I always work around it.
>I either have to check to see if it is the first value I added, and not put the delimiter, which each subsequent value would be delimiter & value,
>or
>after I add all the values, I remove the delimiter from the end.
>
>Either works fine, I was just wondering if there is a more efficient, easier to code, way I could be going about this.
>
>I was looking at the string builder class, and I didn't see this ability, but if I could load all the values, then perform a tostring that would delimit them for me, that would work so much easier! Maybe there are some other objects out there that could do this, or even I could extend the StringBuilderClass
>
>Anyone have any ideas?
>--Michael


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query to delimited string Bill McCormick Microsoft C# .NET 2 15th Oct 2008 04:33 AM
delimited string test rodchar Microsoft C# .NET 3 26th Mar 2008 10:16 PM
Delimited String to Array Kyro Microsoft C# .NET 18 14th Aug 2006 05:45 PM
Piped delimited string to int Fariba Microsoft C# .NET 15 20th Apr 2006 04:56 PM
WORD-DELIMITED string as opposed to character delimited string jackal2k6 Microsoft Access VBA Modules 0 23rd Dec 2005 12:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:38 PM.