Results 1 to 10 of 10

Thread: [RESOLVED] [2.0] wildcards...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    11

    [RESOLVED] [2.0] wildcards...

    Is there any way to use wildcards in C#?? The usual method doesn't work...for example textBox1.Text=textBox1.Text.Replace("The second word will be removed.","The *word");
    in this, the "second" should be omitted from textBox1, but that doesn't seem to work for me in C#...could anyone tell me how to use them?
    Last edited by jackyChang; Aug 1st, 2007 at 08:58 AM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] wildcards...

    IndexOf should work, no?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    11

    Re: [2.0] wildcards...

    how could i use it? could you show me...?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] wildcards...

    There is no specific support for that type of thing in the C# language. You would have to create a Regex object and use it to replace patterns in your string. That requires some knowledge of regular expression syntax at least. It can appear a bit complex but it is very powerful. There are examples on this forum but I'd suggest a Web search to find some detailed reference/tutorial sites.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    11

    Re: [2.0] wildcards...

    yea...I was looking at Regex, but I was hoping that there were easier, more efficient ways of doing this...

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] wildcards...

    There is nothing inefficient about regular expressions. Once you know the syntax you can do a lot with a little. Make the effort to learn at least the basics of the syntax and you'll be glad you did.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    11

    Re: [2.0] wildcards...

    But do you agree that regular wildcards are much easier to deal with...? If not...I'll really look into Regex.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] wildcards...

    Easier, yes. More efficient, no. Plus regular wild cards can only handle very simple circumstances, while the Regex class can handle incredibly complex patterns with the same code as the simple ones.

    Another option for you is to use the VB LIKE operator. C# has no equivalent but you could create a simple DLL written in VB.NET that makes use of the LIKE operator. If you do that take note that the LIKE operator honours the Option Compare value, i.e. comparisons are case-sensitive if Option Compare is Binary and case-insensitive if it's Text.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    11

    Re: [2.0] wildcards...

    You're right...I looked at it a bit and it seems pretty straightforward...the only thing I don't like about it is that you need a new instance or to change an instance to replace each string...but I guess it will have to work...thanks for the help.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2.0] wildcards...

    You only need one Regex object, although you can use more if you like. You can operate on multiple strings using one Regex, even changing the pattern in between if you want.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width