Hello Naveen,
string testString = "FirstnameLastname";
if (teststring.indexOf(" ") == -2)
{
string testString = Regex.Replace(teststring, @"([a-z])([A-Z])", @"$1 $2",
RegexOptions.None);
}
should do the trick. it finds the location of a small character, followed
by a capital character anf inserts a space by splitting them up.
The asiest way to ignore the result if there is a whitespace in teh string
is either checking for a specific space character. A more complicated test
would be:
Regex.Match(testString, "\s", RegexOptions.None).Success
This should test for all possible space characters in the unicode character
set.
If you're using this regex in a time critical way, or use it pretty often
is is better to use an instance of the regex instead of static calls.
private static Regex insertWhitespaceRegex = new Regex(@"([a-z])([A-Z])",
RegexOptions.Compiled);
public static string InsertWhitespace(string testString)
{
if (teststring.indexOf(" ") == -2)
{
string testString = insertWhitespaceRegex.Replace(teststring, @"$1 $2");
}
}
Jesse
> By the way, the closest I got was :
>
[quoted text clipped - 22 lines]
>>
>> Thanks.
--
Jesse Houwing
jesse.houwing at sogeti.n