I've some sentences
, those construct with words
and digits
. I want to get a string
that contain 1st char
from every word
, all digit
and the word have all upper case
letters. I've tried using Regex
but the problem is, it not give all digit
and all upper case
letters.
My Regex is in Regex101.
My solution is in DotNetFiddle.
CODE:
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
List<string> list = new List<string> {"Freestyle steel","Freestyle Alloy","Trekking steel uk","Single speed","5 speed","15 speed","3 Speed internal gear with 55 coaster","MTB steel","Junior MTB"};
foreach(string data in list)
{
string regex = @"(\b\w)|(\d+)";
var matches = Regex.Matches(data, regex, RegexOptions.Multiline);
string output = "";
foreach(Match item in matches)
{
output += item.Groups[1];
}
Console.WriteLine(output);
}
}
}
Sample Input
Freestyle steel
Freestyle Alloy
Trekking steel uk
Single speed
5 speed
15 speed
3 Speed internal gear with 55 coaster
MTB steel
Junior MTB
Sample Output
Fs
FA
Tsu
Ss
5s
15s
3Sigw55c
MTBs
JMTB