Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:23:23+00:00 2026-05-20T09:23:23+00:00

I am converting VBA code that contains the LIKE operator, as in dim sToken

  • 0

I am converting VBA code that contains the LIKE operator, as in

    dim sToken as String
    if sToken Like "(*,*)" then ...

In all cases the patterns use only the * wildcard which matches any string (including the empty string). The VBA Like operator yields only a true/false result so it’s up to the subsequent VBA code to parse further and pluck out the matching substrings whenever there’s a match.

I’d be most appreciative if someone can provide a C# snippet to test for the same type of simple wildcard match. If the snippet also yields matching substrings – even better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:23:23+00:00Added an answer on May 20, 2026 at 9:23 am

    Well, that particular pattern could be matched with

    if (sToken.StartsWith("(") && sToken.EndsWith(")")
        && sToken.Contains(","))
    

    but in general you may find it makes more sense to use regular expressions. For example:

    using System;
    using System.Text.RegularExpressions;
    
    class Program
    {
        static void Main(string[] args)
        {
            Regex regex = new Regex(@"^\(.*,.*\)$");
    
            Console.WriteLine(regex.IsMatch("x(a,b)")); // False due to the x
            Console.WriteLine(regex.IsMatch("(a,b)x")); // False due to the x
            Console.WriteLine(regex.IsMatch("(ab)"));   // False due to the lack of ,
            Console.WriteLine(regex.IsMatch("(a,b"));   // False due to the lack of )
            Console.WriteLine(regex.IsMatch("(a,b)"));   // True!
            Console.WriteLine(regex.IsMatch("(aaa,bbb)"));   // True!
            Console.WriteLine(regex.IsMatch("(,)"));   // True!
        }
    }
    

    Things to note with the pattern here:

    • I’ve used a verbatim string literal (the @ at the start) to make it easier to perform escaping within the regex
    • ^ and $ force it to match the whole string
    • The brackets are escaped so they’re not treated as grouping operators

    The MSDN “Regular Expression Language Elements” page is a good reference for .NET regexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Converting my current code project to TDD, I've noticed something. class Foo { public
I'm converting an application to use Java 1.5 and have found the following method:
I am considering converting a project that I've inherited from .net 1.1 to .net
I'm converting an old app that records folder sizes on a daily basis. The
I am working on converting a CVS repository that has the following symbols (among
About a year ago, a manager in another department brainstormed that I could code
I am currently in the process of converting some excel VBA to C# and
I have an Excel 2003 VBA solution I'm converting to Excel 2007. The solution
Converting non-negative Integer to its list of digits is commonly done like this: import
When converting an int like so: char a[256]; sprintf(a, %d, 132); what's the best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.