Cut in several parts string of characters C # asp.net

0

Good evening.

How can I convert the following string: "image / jpg, image / jpeg, application / pdf" in the following: ".jpg, .pdf, .zip"

Also taking into account that the first chain can include more extensions.

Thank you.

    
asked by afar1793 08.11.2017 в 02:51
source

1 answer

2

You can use regular expressions:

    var cadena = "image/jpg,image/jpeg,application/pdf";
    // Obtenemos las extensiones
    var result = Regex.Matches(cadena, @"\w+/(\w+)")
        .Cast<Match>().Select(x => $".{x.Groups[1].Value}");
    // Concatena las extensiones utilizando la , como separador
    Console.WriteLine(string.Join(",", result));
    
answered by 08.11.2017 в 09:06