user1438082
user1438082

Reputation: 2748

Get Names from string values

I have a string as shown below.

How do i extract the name from both such that for the example below the result would be:

Input String:

\\DF3\root\cimv2:Win32_Group.Domain="DF3",Name="Administrators"

Output:

Administrators

Upvotes: 0

Views: 101

Answers (2)

Dexters
Dexters

Reputation: 2495

You can use the regex to match what you want.. in case you dont want to use split

using System.IO;
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        var input = "\\DF3\\root\\cimv2:Win32_Group.Domain=\"DF3\",Name=\"Administrators\"";
        Console.WriteLine(Regex.Match(input, "Name=\\\"(.*?)\\\"").Groups[1].Value);
    }
}

Upvotes: 1

Selman Genç
Selman Genç

Reputation: 101681

You can do something like this:

var input = "\\DF3\\root\\cimv2:Win32_Group.Domain=\"DF3\",Name=\"Administrators\"";

var name = input.Split(new[] { "Name=" }, StringSplitOptions.None)
                .Last().Trim('"');

First Split your string by Name=, get the last part then use Trim and remove the double-quotes.

Upvotes: 2

Related Questions