A Linq to replace unwanted characters

Erçin Dedeoğlu

I have a Linq code to get acceptable characters and remove others. But this code replace others with ""(nothing + null+ string.empty etc) I would like to replace with space ( ). How can I do it?

Thanks a lot.

string clean = new string(incomingText.Where(c => @" 0123456789abcçdefgğhıijklmnöopqrsştuüvwxyz".Contains(c)).ToArray());
Jon Skeet

Well you could use:

// Alternatively use a HashSet<char>
string acceptableCharacters = " 1234...";
string clean = new string(incomingText.Select(c => acceptableCharacters.Contains(c) ?
                                                   c : ' ')
                                      .ToArray());

Note that this still really isn't terribly efficient. I'd probably use a call to Regex.Replace instead.

Regex invalidCharacterPattern = new Regex("[^ 0-9a-zçğıöşü]");
string clean = invalidCharacterPattern.Replace(incomingText, " ");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

preg_replace remove all unwanted characters

From Dev

Replace unwanted characters for filename in Visual Basic

From Dev

Can you construct a RegEx to replace unwanted characters with the underscore?

From Dev

PHP preg_replace unwanted characters and echo a message if such characters are found in the string

From Dev

How to remove unwanted characters?

From Dev

Unwanted Characters in CSV

From Dev

Trimming unwanted characters

From Dev

how to replace unwanted characters and digits from time column and combine with date column in the dataframe?

From Dev

Linq unwanted list

From Dev

Using LINQ lambda to replace characters from array in string

From Dev

Using LINQ lambda to replace characters from array in string

From Java

How to remove unwanted characters in python

From Dev

jQuery adding unwanted characters to string?

From Dev

Unwanted translation of newline characters in PostgreSQL

From Dev

Unwanted spaces around characters in regex

From Dev

Unwanted characters in regular expressions python

From Dev

HttpGet getting text with unwanted characters

From Dev

Unwanted characters after word in output

From Dev

How to clear unwanted characters in bash

From Dev

Javascript RegExp returning unwanted characters

From Dev

Unwanted characters in regular expressions python

From Dev

not allowing unwanted characters to input in a field

From Dev

Beautiful Soup Returning Unwanted Characters

From Dev

Remove unwanted characters in given format

From Dev

Sed matches unwanted extra characters

From Dev

LINQ retains unwanted data binding

From Dev

How to remove unwanted characters but preserve specific characters

From Java

How to replace unwanted text on beautifulsoup

From Dev

unwanted partial matches with Python replace

Related Related

  1. 1

    preg_replace remove all unwanted characters

  2. 2

    Replace unwanted characters for filename in Visual Basic

  3. 3

    Can you construct a RegEx to replace unwanted characters with the underscore?

  4. 4

    PHP preg_replace unwanted characters and echo a message if such characters are found in the string

  5. 5

    How to remove unwanted characters?

  6. 6

    Unwanted Characters in CSV

  7. 7

    Trimming unwanted characters

  8. 8

    how to replace unwanted characters and digits from time column and combine with date column in the dataframe?

  9. 9

    Linq unwanted list

  10. 10

    Using LINQ lambda to replace characters from array in string

  11. 11

    Using LINQ lambda to replace characters from array in string

  12. 12

    How to remove unwanted characters in python

  13. 13

    jQuery adding unwanted characters to string?

  14. 14

    Unwanted translation of newline characters in PostgreSQL

  15. 15

    Unwanted spaces around characters in regex

  16. 16

    Unwanted characters in regular expressions python

  17. 17

    HttpGet getting text with unwanted characters

  18. 18

    Unwanted characters after word in output

  19. 19

    How to clear unwanted characters in bash

  20. 20

    Javascript RegExp returning unwanted characters

  21. 21

    Unwanted characters in regular expressions python

  22. 22

    not allowing unwanted characters to input in a field

  23. 23

    Beautiful Soup Returning Unwanted Characters

  24. 24

    Remove unwanted characters in given format

  25. 25

    Sed matches unwanted extra characters

  26. 26

    LINQ retains unwanted data binding

  27. 27

    How to remove unwanted characters but preserve specific characters

  28. 28

    How to replace unwanted text on beautifulsoup

  29. 29

    unwanted partial matches with Python replace

HotTag

Archive