Solved

Strip parenthesis and contents

Posted on 2009-05-13
6
279 Views
Last Modified: 2013-12-17
Dear Experts,

In one of our transaction, we add something like "(Free 12BX) or (Free ##IU)" as a note in addition to the product description as:

Borgesic Forte, tablet 100's (Free ##IU)  -- ## is the quantity and IU is the Issue Unit (could be BX, PC, EA, FT, Etc)

In the issuance transaction however, I want to strip out "(Free ##IU)" to keep the original description as:

Borgesic Forte, tablet 100's

So basically what I need is stripping:

"Borgesic Forte, tablet 100's (Free ##IU)"  to "Borgesic Forte, tablet 100's"  

where "(Free"  is constant and "##IU" varies.  


Thanks.
0
Comment
Question by:JaimeJegonia
  • 4
6 Comments
 
LVL 5

Assisted Solution

by:Aanvik
Aanvik earned 25 total points
ID: 24380740
Try replace function. Replace with blank string. You can also use Substring function.

http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx
0
 
LVL 39

Accepted Solution

by:
abel earned 275 total points
ID: 24380753
Assuming that the string ends with a closing parenthesis and assuming that there are not other closing parentheses between the opening and the closing parentheses, you can do this:

// replace anything between the parentheses, incl. leading space and any content

string newString = Regex.Replace("Borgesic Forte, tablet 100's (Free ##IU)", @"\s*\([^)]+\)$", "");

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24380754
Sorry, Aanvik, missed your post.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 39

Expert Comment

by:abel
ID: 24380774
Anyway, if you are not accustomed to regexes, it can look daunting at first (you may need a using System.Text on top of your class), so let's explain them a bit:

@"..."
the opening @-sign makes the string literal, no need for escaping backslashes as "\\" anymore
\s*
the "\s" means whitespace and the * means zero or more

\(
the "(" is special in a regex. To use the literal, it must be escaped, hence "\("
[^)]+
the tricky bit: grab everything not a closing a parenthesis and grab one or more (the + sign)
\)
the closing parenthesis needs to be escaped too

$
the dollar sign means "match end of string". That means that closing parenthesis must be at the end of the string for the replacement to work. If that is not always the case, remove it, or change it to accomodate these other possibilities.

-- Abel --
0
 

Author Closing Comment

by:JaimeJegonia
ID: 31581272
Abel, thanks for quick solution and excellent tips.
0
 
LVL 39

Expert Comment

by:abel
ID: 24382454
you're welcome, always glad to be of help :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

11 Experts available now in Live!

Get 1:1 Help Now