VB6 and C # Modes

I need to convert a VB6 project (which I don't know) to C # 4.0. The project contains several regular expressions to check the string.

I need to know if the regular expressions will be the same in both cases, so if I just copy the regular expression string from the VB6 project to the C # project, will they work the same?

I have a basic knowledge of regular expressions, and I can just read what he does, but for fragrances and the like, which are a little on my head at the moment.

For example, are these 2 lines equivalent?

VB6:

isStringValid = (str Like "*[!0-9A-Z]*") 

WITH#:

 isStringValid = Regex.IsMatch(str, "*[!0-9A-Z]*"); 

Thanks!

+4
source share
2 answers

The old VB Like operator, despite its appearance, is not a regex interface. This is more like a template. See http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx

In your example:

 Like "*[!0-9A-Z]*" 

Matches strings that begin and end with any character (zero or more), and then do not match an alphanumeric character somewhere in the middle. A regular expression for this would be:

 /.*[^0-9A-Z].*/ 

EDIT To answer your question: No, these two options cannot be used interchangeably. However, it is fairly easy to convert the Like operand to the correct regular expression:

 Like RegEx ========== ========== ? . * .* # \d [abc0-9] [abc0-9] [!abc0-9] [^abc0-9] 

There are a few caveats to this, but this should get you started and cover most cases.

+9
source

In a word, yes.

It is the same. Some quick searches should give you answers to more complex questions.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/bce145b8-95d4-4be4-8b07-e8adee7286f1/

http://www.regular-expressions.info/dotnet.html

-1
source

Source: https://habr.com/ru/post/1438909/


All Articles