C#: splitting a string and not returning empty string

String.Split takes an array when including any StringSplitOptions: string[] batchstring = batch_idTextBox.Text.Split(new [] { ‘;’ }, StringSplitOptions.RemoveEmptyEntries); If you don’t need options, the syntax becomes easier: string[] batchstring = batch_idTextBox.Text.Split(‘;’);

Understanding regex in Java: split(“\t”) vs split(“\\t”) – when do they both work, and when should they be used

When using “\t”, the escape sequence \t is replaced by Java with the character U+0009. When using “\\t”, the escape sequence \\ in \\t is replaced by Java with \, resulting in \t that is then interpreted by the regular expression parser as the character U+0009. So both notations will be interpreted correctly. It’s just … Read more

C# Regex.Split: Removing empty results

Regex lineSplitter = new Regex(@”[\s*\*]*\|[\s*\*]*”); var columns = lineSplitter.Split(data).Where(s => s != String.Empty); or you could simply do: string[] columns = data.Split(new char[] {‘|’}, StringSplitOptions.RemoveEmptyEntries); foreach (string c in columns) this.textBox1.Text += “[” + c.Trim(‘ ‘, ‘*’) + “] ” + “\r\n”; And no, there is no option to remove empty entries for RegEx.Split as … Read more

tech