add space in string

  • Thread starter Thread starter NuCoder
  • Start date Start date
N

NuCoder

I'm getting a string like this

BMWLEXUSBMWMERCEDES
how can I add a space so it looks like this

BMW, LEXUS, BMW, MERCEDES
 
NuCoder said:
I'm getting a string like this

BMWLEXUSBMWMERCEDES
how can I add a space so it looks like this

BMW, LEXUS, BMW, MERCEDES

Well, you'll have to know what to split the string on first - do you
have a predefined list of tokens that the string will be comprised of?
 
unfortuneally no, it can be in any order at any given time, so I don't have
any predefined list.
 
NuCoder said:
unfortuneally no, it can be in any order at any given time, so I don't have
any predefined list.
The order may be variable but you _will_ have to have some sort of list
that defines the words you wish to separate.

string[] Cars = new string[3]{"BMW", "LEXUS", "MERCEDES"};

After that, say you have an array of strings containing your words, you
can do:

string FullString = "BMWLEXUSBMWMERCEDES";
foreach(string Car in Cars)
{
FullString = FullString.Replace(Car, Car + ", ");
}

JB
 
NuCoder said:
unfortuneally no, it can be in any order at any given time, so I don't have
any predefined list.

In that case there's no correct answer. For instance, what should the
following be split as:

AKJHASDLASDJKHKAJSHDKJHALXACADHKCIDQTOUO

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

string question 6
group dataset 4
VLOOKUP or MATCH or Magical function 8
loop through dataset 4
array question 8
text file format 1
select listbox 1
About generics 9

Back
Top