473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Like Operator

In the old Visual Basic I could do something like this

myCheck = "aBBBa" Like "a*a"

The return value would be true. Is there a way for comparing strings in C#
were I can use wild characters like * etc?
Nov 15 '05 #1
7 1372
"Rene" <no****@nospam.com> wrote in
news:u7**************@TK2MSFTNGP11.phx.gbl:
In the old Visual Basic I could do something like this

myCheck = "aBBBa" Like "a*a"

The return value would be true. Is there a way for comparing
strings in C# were I can use wild characters like * etc?


The .Net framework provides regular expressions:
using System.Text.RegularExpressions;
...
bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #2
Your pattern string has a "^" a "." a "*" and a "$". Could you please tell
me what all this symbols are for? I recognize the reason for the "*" but I
have no idea what the others are there for! I didn't find this info in the
documentation.

Thank you.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
"Rene" <no****@nospam.com> wrote in
news:u7**************@TK2MSFTNGP11.phx.gbl:
In the old Visual Basic I could do something like this

myCheck = "aBBBa" Like "a*a"

The return value would be true. Is there a way for comparing
strings in C# were I can use wild characters like * etc?


The .Net framework provides regular expressions:
using System.Text.RegularExpressions;
...
bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 15 '05 #3
"^" means the beginning of the string. If you left this out, it would match
things like XYZaBBBa

"." means any character and ".*" means any number (zero or more) of any
character

"$" means the end of the string. If you left this out, it would match things
like aBBBaXYZ
"Rene" <no****@nospam.com> wrote in message
news:ej*************@tk2msftngp13.phx.gbl...
Your pattern string has a "^" a "." a "*" and a "$". Could you please tell
me what all this symbols are for? I recognize the reason for the "*" but I
have no idea what the others are there for! I didn't find this info in the
documentation.

Thank you.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
"Rene" <no****@nospam.com> wrote in
news:u7**************@TK2MSFTNGP11.phx.gbl:
In the old Visual Basic I could do something like this

myCheck = "aBBBa" Like "a*a"

The return value would be true. Is there a way for comparing
strings in C# were I can use wild characters like * etc?


The .Net framework provides regular expressions:
using System.Text.RegularExpressions;
...
bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/


Nov 15 '05 #4
Thank you, that really helped.

Could you please tell me where can I find this information (web link or
something similar) so that I can take a closer look and see what else I can
learn about comparing string?

Thank you.

"Bret Mulvey" <br***@microsoft.nospam0000.com> wrote in message
news:1Uvdb.611823$uu5.99847@sccrnsc04...
"^" means the beginning of the string. If you left this out, it would match things like XYZaBBBa

"." means any character and ".*" means any number (zero or more) of any
character

"$" means the end of the string. If you left this out, it would match things like aBBBaXYZ
"Rene" <no****@nospam.com> wrote in message
news:ej*************@tk2msftngp13.phx.gbl...
Your pattern string has a "^" a "." a "*" and a "$". Could you please tell me what all this symbols are for? I recognize the reason for the "*" but I have no idea what the others are there for! I didn't find this info in the documentation.

Thank you.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn*********************************@207.46.24 8.16...
"Rene" <no****@nospam.com> wrote in
news:u7**************@TK2MSFTNGP11.phx.gbl:

> In the old Visual Basic I could do something like this
>
> myCheck = "aBBBa" Like "a*a"
>
> The return value would be true. Is there a way for comparing
> strings in C# were I can use wild characters like * etc?

The .Net framework provides regular expressions:
using System.Text.RegularExpressions;
...
bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/



Nov 15 '05 #5
Rene <no****@nospam.com> wrote:
Thank you, that really helped.

Could you please tell me where can I find this information (web link or
something similar) so that I can take a closer look and see what else I can
learn about comparing string?


Look up "regular expressions" in the MSDN, and you should find a lot of
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Rene wrote:
Your pattern string has a "^" a "." a "*" and a "$". Could you please
tell me what all this symbols are for? I recognize the reason for the
"*" but I have no idea what the others are there for! I didn't find
this info in the documentation.


Look for "regular expressions" in the index of the .NET docs. You'll find
a huge range of topics about it.
--
Rudy Velthuis

"Before C++ we had to code all of our bugs by hand; now we inherit
them." -- unknown
Nov 15 '05 #7
MSDN has documentatioin for this at
http://msdn.microsoft.com/library/en...ularexpression
slanguageelements.asp
"Rene" <no****@nospam.com> wrote in message
news:eR**************@TK2MSFTNGP12.phx.gbl...
Thank you, that really helped.

Could you please tell me where can I find this information (web link or
something similar) so that I can take a closer look and see what else I can learn about comparing string?

Thank you.

"Bret Mulvey" <br***@microsoft.nospam0000.com> wrote in message
news:1Uvdb.611823$uu5.99847@sccrnsc04...
"^" means the beginning of the string. If you left this out, it would match
things like XYZaBBBa

"." means any character and ".*" means any number (zero or more) of any
character

"$" means the end of the string. If you left this out, it would match

things
like aBBBaXYZ
"Rene" <no****@nospam.com> wrote in message
news:ej*************@tk2msftngp13.phx.gbl...
Your pattern string has a "^" a "." a "*" and a "$". Could you please tell me what all this symbols are for? I recognize the reason for the "*"
but I have no idea what the others are there for! I didn't find this info in the documentation.

Thank you.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn*********************************@207.46.24 8.16...
> "Rene" <no****@nospam.com> wrote in
> news:u7**************@TK2MSFTNGP11.phx.gbl:
>
> > In the old Visual Basic I could do something like this
> >
> > myCheck = "aBBBa" Like "a*a"
> >
> > The return value would be true. Is there a way for comparing
> > strings in C# were I can use wild characters like * etc?
>
> The .Net framework provides regular expressions:
>
>
> using System.Text.RegularExpressions;
> ...
> bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");
>
>
> Hope this helps.
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/



Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Arvid Andersson | last post by:
Hello, I need to convert a string to a number, but the string can contain +,-,* and / as well as parenthesis. For example, if I have the string "30/(6+9)" I would like a function that returned the...
0
by: Jason Heyes | last post by:
I wrote a previous post that asked whether there was a reference-counted implementation of std::vector. Apparantly there wasn't. So my next question is, is it possible to write your own shared...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
3
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would...
9
by: Rich Herrick | last post by:
The latest version of my "Pascal-like" set class is available here: http://www.richherrick.com/software/herrick-1.0.zip Those from the old YAHOO BOOST forum might remember it from several...
2
by: Ed Brown | last post by:
I'm working on a VB.Net application that needs to do quite a bit of string pattern matching, and am having problems using the "LIKE" operator to match the same string twice in the pattern. For...
12
by: ex_ottoyuhr | last post by:
I have a situation more or less as follows, and it's causing me no end of trouble; I'd appreciate anyone's advice on the matter... Given these classes: class BedrockCitizen { ... }; class...
2
by: Piotr Sawuk | last post by:
What is wrong with the following? Why doesn't it compile? template<int f, class me, typename ValType=int> class Fm { protected: ValType v; public: me& operator+=(const me& o)...
4
by: Christian Schmidt | last post by:
Hi all, I'm trying to implement a std::vector-like wrapper for IList. The hard part seems to be operator, because it returns an unmanaged reference. Probably I have to use pin_ptr to achieve this,...
5
by: simudream | last post by:
//hi maybe helpful others can look at this code and //tell me why the class code won't behave like //intrinsic types with post and pre increment //Version: 1.00 #include <iostream> using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.