How can I break up the text after the # I shared in the image?

117 Views Asked by At

enter image description here

  • I will create a parametric structure
  • I will take after each '#' with its extension.
  • For example here I need to get two texts after #
1

There are 1 best solutions below

0
joseph l On
string text = "#sdvdsv0..-+mk?/!|°¬  *$%&()oO###sdfv684618awer6816";

string[] results = Regex.Split(text, "#+").Where(s => s != String.Empty).ToArray<string>(); 

Full example on a .net 6.0 console:

using System.Text.RegularExpressions;

string text = "#sdvdsv0..-+mk?/!|°¬  *$%&()oO###sdfv684618awer6816";

string[] results = Regex.Split(text, "#+").Where(s => s != String.Empty).ToArray<string>(); 

foreach (var x in results)
{
    Console.WriteLine(x);
}

Output:

sdvdsv0..-+mk?/!|°¬  *$%&()oO
sdfv684618awer6816

Use "#" to match only a single # character.

Use "#+" to match at least once with the # character