Solved

how to clear a string that has multiple characters in it

Posted on 2013-11-25
5
210 Views
Last Modified: 2013-11-25
OK I return a value from a COM port as the following:

<ack,123456CR<DR,1.56,123456CR

I am trying to key off two values that are duplicated in this string and if this is the case then clear the string and move on. If the string has the following sames characters "<" or "CR" which is Carriage return

How can I look at the string see that it carries two of the same values listed above and clear the string.
0
Comment
Question by:cmdolcet
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 305 total points
ID: 39675705
A regular expression could handle this.

e.g.

If System.Text.RegularExpressions.Regex.IsMatch(inputString, "([<\r]).*?\1") Then
    inputString = String.Empty
End If

Open in new window


The square brackets mean "either of these". The parentheses capture what is matched. The "\1" refers to this capture group. And the ".*?" means to match anything in between (including nothing). The overall effect is to match two of the same character (that you specified in the brackets) with anything in between.
0
 

Author Comment

by:cmdolcet
ID: 39675711
OK would it still be valid if the message was "<ack,123456CR" ?
because that is still acceptable
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39675718
What do you mean by "valid". I took your original post to mean that you either would find two angle-brackets or two carriage returns, not one angle bracket and one carriage return. If there are not two (or more) of the same exact character in the string, then the string is left alone.
0
 

Author Comment

by:cmdolcet
ID: 39675770
OK I just had to make a slight change on your ismatch condition It was throwing an error saying it was missing a ")" so I added the following in "([\r].*?\1")  and then it did trigger an error however it is not picking up the invalid string.
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 305 total points
ID: 39675785
There needs to be a closing paren to the right of the closing square bracket.

Here's just the string:

"([\r]).*?\1"

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now