0

I am looking for some solution to my problem, here is what i need, just an example i have phrase

"ProgrammingIsIntresting"

i need it to split and make a string like "Programming Is Intresting".

CultureInfo.CurrentCulture.TextInfo.ToTitleCase work here but how can i put space literal here.

here is what i have and it seems i am stuck here.

var UpperChars = mystring.Where(c => Char.IsUpper(c));
                        foreach (var ch in UpperChars)
                        {
                            if (mystring.IndexOf(ch) == 0)
                                continue;

                        }
A.T.
  • 24,694
  • 8
  • 47
  • 65

3 Answers3

3

Try this:

return Regex.Replace(input, "([A-Z])"," $1", RegexOptions.Compiled).Trim();

from http://weblogs.asp.net/jgalloway/archive/2005/09/27/426087.aspx

or:

var splitted = Regex.Replace("ProgrammingIsIntresting", 
                    @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");

second one will deal with SQLIsCool example

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
1
 string myString = "ProgrammingIsIntresting";
 String newString = "";
 char intermediate;
 for (int i = 0; i < myString.Length; i++)
 {
     intermediate = myString[i];
     if(char.IsUpper(intermediate) && (i != 0))
       newString = newString + " " + intermediate.ToString();
     else
       newString = newString + intermediate.ToString();
 } 
 Console.WriteLine(newString);
manish
  • 1,450
  • 8
  • 13
0

Another possible approach could be this which I just tried:

    string a = "IAmVahid";
    List<char> b= new List<char>();
    int j = 0;

    for (int i = 0; i < a.Length; i++)
    {
        if (char.IsUpper(a[i]))
        {
            b.Add(' ');
        }
        b.Add(a[i]);
    }

    ouputTxt.Text = new String(b.ToArray()) ;
Vahid Nateghi
  • 576
  • 5
  • 14