Solved

Strip parenthesis and contents

Posted on 2009-05-13
6
283 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
[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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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