|
-
Jul 31st, 2007, 06:10 PM
#1
Thread Starter
New Member
[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.
-
Jul 31st, 2007, 07:51 PM
#2
Frenzied Member
-
Jul 31st, 2007, 07:53 PM
#3
Thread Starter
New Member
Re: [2.0] wildcards...
how could i use it? could you show me...?
-
Jul 31st, 2007, 08:02 PM
#4
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.
-
Jul 31st, 2007, 08:04 PM
#5
Thread Starter
New Member
Re: [2.0] wildcards...
yea...I was looking at Regex, but I was hoping that there were easier, more efficient ways of doing this...
-
Jul 31st, 2007, 08:10 PM
#6
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.
-
Jul 31st, 2007, 08:16 PM
#7
Thread Starter
New Member
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.
-
Jul 31st, 2007, 08:52 PM
#8
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.
-
Aug 1st, 2007, 08:58 AM
#9
Thread Starter
New Member
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.
-
Aug 1st, 2007, 05:43 PM
#10
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|