I want to space after certain string. for example:
string str = "DASEULE"
Now, I want to add a space after "DAS"
and it will write to UI Text as "DAS EULE"
. How can i do this?
Thanks
Edit: the all chars are uppercase. Sorry
I want to space after certain string. for example:
string str = "DASEULE"
Now, I want to add a space after "DAS"
and it will write to UI Text as "DAS EULE"
. How can i do this?
Thanks
Edit: the all chars are uppercase. Sorry
Try:
string s1 = "DasEule";
s1.Replace("Das", "Das ");
Or
string s2 = "DasEule";
s2.Insert(2, " ");
Not the best code in the world, check the problem mentioned in the question comments, but should work. Is a variant of Ren's answer.
private string AddSpacesIfNecessary(string word)
{
string[] prefixes = new string[] { "DAS", "DIE", "DER" }; // Add other prefixes
foreach(string prefix in prefixes)
{
if(word.StartsWith(prefix))
{
return word.Insert(prefix.Length - 1, " ");
}
}
// Prefixes are not found, no need to add spaces
return word;
}