Split string at every Uppercase character in C#
To split string based on uppercase on C#, we can use regular expressionRegex.split
which can take 2 parameters: first parameter will be the string, second parameter will be the expression.Example
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string str = "hello A user";
string[] split = Regex.Split(str, @"(?<!^)(?=[A-Z])");
Console.WriteLine(split[0]);
Console.WriteLine(split[1]);
}
}
Output
hello
A user
A user