正規表現とリンクの組み合わせを使用すると、次のことができます。
using System.Text.RegularExpressions;
using System.Linq;
var str="asd fds 1.4#3";
var regex=new Regex("([A-Za-z]+)|([0-9]+)|([.#]+)|(.+?)");
var result=regex.Matches(str).OfType<Match>().Select(x=>x.Value).ToArray();
Add additional capture groups to capture other differences. The last capture (.+?)
is a non greedy everything else. So every item in this capture will be considered different (including the same item twice)
Update - new revision of regex
var regex=new Regex(@"(?:[A-Za-z]+)|(?:[0-9]+)|(?:[#.]+)|(?:(?:(.)\1*)+?)");
This now uses non capturing groups so that \1
can be used in the final capture. This means that the same character will be grouped if its in then catch all group.
e.g. before the string "asd fsd" would create 4 strings (each space would be considered different) now the result is 3 strings as 2 adjacent spaces are combined