Solved

how to clear a string that has multiple characters in it

Posted on 2013-11-25
5
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

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 75

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 75

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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