Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get character after certain character from a String

Tags:

string

c#

I need to get a characters after certain character match in a string. Please consider my Input string with expected resultant character set.

Sample String

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

Resultant string

Twoo

I have done this

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

Any help to this will be appreciated.

Thanks

like image 530
DonMax Avatar asked May 23 '26 13:05

DonMax


1 Answers

LINQ solution:

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);
like image 184
Selman Genç Avatar answered May 26 '26 08:05

Selman Genç