Solved

regular expression replaceif the thereis a non alpha numeric charters at the end of the string

Posted on 2014-09-11
3
189 Views
Last Modified: 2014-09-15
I wnat to replace with empty string if there is an apha numeric character at the end of the string
0
Comment
Question by:Angela4eva
3 Comments
 

Author Comment

by:Angela4eva
ID: 40317496
I want to replace that chacters only

test1234*
then  return test1234
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 40318837
Hi,

pls try

"test1234*".Replace("\W$", "");

Regards
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 40320397
@Rgonzo1971's solution allows underscore characters to remain at the end of the string. It also only removes the last non-alphanumeric character when there are more than one. To fix both those issues, use:
"test1234*".Replace("[^a-zA-Z0-9]+$", "");

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB.net PaintEventArgs Handling. 10 28
Convert string to date 3 40
What .NET website keeps me current? 9 32
ASP.NET reading ATOM 2 27
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

10 Experts available now in Live!

Get 1:1 Help Now