none
Help With Searching Through A String Pls :) RRS feed

  • Question

  • Hey anyone who decides to read this, I'm trying to find a way to search through a string the user inputs for every occurance of the phrase "example(" then find everything between that bracket and the ")" that will close it, and store the contents of the bracket in a variable. Any help? I've messed around a bit with Substring and IndexOf but I haven't been able to come up with anything that works the way I have indended. I also want it to miss out brackets that don't have "example" before them. Any help is appreciated, thanks :)

    \/\/\Syko/\/\/

    Edit: C# please :) 
    Monday, June 10, 2019 7:05 PM

Answers

All replies

  • You could use a regular express for matching this

                Regex regBracket = new Regex(@"example+[ ]\(.*?\)");
                string text = "(one) and (two) three example (four strings)";
                foreach (var match in regBracket.Matches(text))
                {
                    Console.WriteLine(match);
                }

    Tuesday, June 11, 2019 12:15 AM
  • Hi Sykotic_Cataclysm,

    Welcome to the MSDN forum.

    According to the description, this issue is about the C# development and our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum for better support, thanks for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, June 11, 2019 9:08 AM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 25, 2019 8:44 AM
    Moderator