0

hello everybody how i can get NGG - Acid

from this string

"????log L 06/11/2012 - 06:45:28: \"NGG - Acid<5><STEAM_ID_PENDING><>\" connected, address \"46.49.70.30:27005\"\n\0"

I have tried this

int start = Data.ToString().IndexOf('"') + 1;
            int end = Data.ToString().IndexOf('<');
            return Data.ToString().Substring(start, end - start);

This does not works when username contains space or symbols

Thank you

Update this code gets username but is there better solution:

if (Data.EndsWith("\"")) Data = Data.Substring(0, Data.Length - 1);
            int start = Data.IndexOf("\"");
            int end = Data.IndexOf("<");
            var val = Data.Substring(start + 1, end - 1 - start);
1
  • 3
    What part in your string is a user name? Commented Jun 11, 2012 at 13:57

2 Answers 2

1

Your match will be in group 1 of

\\"(.*?)<

If we suppose your desired match is between \" and <

In C# this becomes

var c = Regex.Match(@"""????log L 06/11/2012 - 06:45:28: \""NGG - Acid<5><STEAM_ID_PENDING><>\"" connected, address \""46.49.70.30:27005\\""\n\0"""
, @"\\""(.*?)<").Groups[1].Value;
Sign up to request clarification or add additional context in comments.

1 Comment

please see my comment on Khôi`s comment
1

If you want to use a regex:

Match match = Regex.Match(Data, @"\\""(.+?)<\d+?><ST");

if (match.Success) {
    Console.WriteLine(match.Groups[1].Value);
}

2 Comments

Thank you but if user name is Acid< it gives only Acid or if name is <Acid result would be empty
Edited my Regex... but it's always hard to parse logs like this, because there are always cases where it doesn't work properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.