Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Friday, 27 October 2017

Remove Unwanted Characters From String In C#

 asp.net, Asp.Net C#, C#, guruji point, Gurujipoint, LINQ, remove unwanted character from string     No comments   


Introduction
In this article we will learn how to remove unwanted character or words from a string in c#. Remove unwanted characters from a string using LINQ. 

Previous Updates
In previous articles we have learnt Showing Chart With Database In Asp.Net Using C#. Maintain state of dynamic added userConrol in asp.net using c#. 

Description:
I have faced one scenerio when any characters can appear in my input string, and I only want to keep the characters that I want (without messing up the order of course). So here is the best practice to remove that unwanted characters from string.
Remove Special Character from a String using Regex
class Program
{
  static void Main(string[] args)
  {
string filteredString = RemoveUnwantedCharacters("*73AB-#g@JP__0328hf014num98k",
                                         "AB-0123456789@JP%-.".ToCharArray());
   }
private static string RemoveUnwantedCharacters(string input,
                                                char[] allowedCharacters)
 {
            var filtered = input.ToCharArray()
                .Where(c => allowedCharacters.Contains(c))
                .ToArray();

            return new String(filtered);
 }
}


Insert
 Only Numeric values in Asp Textbox using Regex.

Output:
In output it will returnall the characters which are pass as allowedCharacters and remove all other character from input .
73AB-@JP032801498
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home
View mobile version

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write