Get character after specific character from string

I need to get characters after a specific character match in a string. Please consider my input line with the expected result character set.

Line example

*This is a string *with more than *one blocks *of values.

Result string

Twoo

I did it

string[] SubIndex = aut.TagValue.Split('*');
            string SubInd = "";
            foreach (var a in SubIndex)
            {
                SubInd = SubInd + a.Substring(0,1);
            }

Any help on this would be appreciated.

thank

+3
source share
6 answers

LINQ decision:

var str = "*This is a string *with more than *one blocks *of values.";
var chars = str.Split(new char[] {'*'}, StringSplitOptions.RemoveEmptyEntries)
               .Select(x => x.First());
var output = String.Join("", chars);
+5
source
string s = "*This is a string *with more than *one blocks *of values.";
string[] splitted = s.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
string result = "";
foreach (string split in splitted)
    result += split[0];
Console.WriteLine(result);
+3
source

Below code should work

var s = "*This is a string *with more than *one blocks *of values."
while ((i = s.IndexOf('*', i)) != -1)
{
    // Print out the next char
    if(i<s.Length)
            Console.WriteLine(s[i+1]);

    // Increment the index.
    i++;
}
+2
source
String.Join("",input.Split(new char[]{'*'},StringSplitOptions.RemoveEmptyEntries)
                    .Select(x=>x.First())
           );
+1
source
string strRegex = @"(?<=\*).";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline | RegexOptions.Singleline);
string strTargetString = "*This is a string *with more than *one blocks *of values.";
StringBuilder sb = new StringBuilder();    
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
    if (myMatch.Success) sb.Append(myMatch.Value);
}
string result = sb.ToString();
0
source

see below...

char[] s3 = "*This is a string *with more than *one blocks *of values.".ToCharArray();
StringBuilder s4 = new StringBuilder();
for (int i = 0; i < s3.Length - 1; i++)
{
   if (s3[i] == '*')
     s4.Append(s3[i+1]);
}
Console.WriteLine(s4.ToString());
0
source

All Articles