W
Webgour
How to go from string "abc" to string "a|b|c"?
Nicholas Paldino said:Webgour,
I would cycle through the characters, and then append the items in a new
StringBuilder, like so:
public static string DelimitString(string value, string delimiter)
{
// If value is null or has zero length, then return value.
// If delimiter is null or has zero length, then return value.
if (value == null || value.Length == 0 || delimiter == null ||
delimiter.Length == 0)
// Get out.
return value;
// Create a string builder, allocate the space equal the length of the
delimiter plus one times
// the number of characters in the string.
StringBuilder pobjBuilder = new StringBuilder((delimiter.Length + 1) *
value.Length;
// Cycle through the characters.
foreach (char pchrChar in value)
{
// Append the character.
pobjBuilder.Append(pchrChar);
// Append the delimiter.
pobjBuilder.Append(delimiter);
}
// Return the string.
return pobjBuilder.ToString();
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Webgour said:How to go from string "abc" to string "a|b|c"?
Webgour said:How to go from string "abc" to string "a|b|c"?
A simple solution...don't know whether this is what you r looking for.