473,659 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove accent marks from text?

MC
Is there a string function in .NET that will remove the accent marks from letters? I know that's a slightly vague request... and that I could implement it by table lookup (and will do so unless something's already there). But can it be accomplished by switching a string among "cultures" or something like that?
Oct 27 '08 #1
4 9910

"MC" wrote:
Is there a string function in .NET that will remove the accent marks from letters? I know that's a slightly vague request... and that I could implement it by table lookup (and will do so unless something's already there). But can it be accomplished by switching a string among "cultures" or something like that?
Hi,

You can remove non spacing characters (and possibly modifier characters)
from the string if you normalize it. This will effectively remove accents
(diacritics) as well.

string normalizedStrin g = regularString.N ormalize(Normal izationForm.For mD);

StringBuilder sb = new StringBuilder(n ormalizedString );

for (int i = 0; i < sb.Length; i++)
{
if (CharUnicodeInf o.GetUnicodeCat egory(sb[i]) ==
UnicodeCategory .NonSpacingMark )
sb.Remove(i, 1);
}
regularString = sb.ToString();

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 27 '08 #2
MC
You can remove non spacing characters (and possibly modifier characters)
from the string if you normalize it. This will effectively remove accents
(diacritics) as well.
Thanks. I should have been clearer. Not only do I want to remove non-spacing characters, I also want to change accented letters to the corresponding unaccented letters. (This is for matching up foreign names... somebody long ago decided the database needed to be in plain ASCII.)
Oct 27 '08 #3
"MC" <fo************ **@www.ai.uga.e du.slash.mcwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>You can remove non spacing characters (and possibly modifier characters)
from the string if you normalize it. This will effectively remove
accents
(diacritics) as well.

Thanks. I should have been clearer. Not only do I want to remove
non-spacing
characters, I also want to change accented letters to the corresponding
unaccented letters. (This is for matching up foreign names... somebody
long
ago decided the database needed to be in plain ASCII.)
Here's hoping no one has used alternate spellings, like <letter>+e for
German umlauted letters. And will the es-tset get translated to "ss"...?
Oct 27 '08 #4

"MC" wrote:
You can remove non spacing characters (and possibly modifier characters)
from the string if you normalize it. This will effectively remove accents
(diacritics) as well.

Thanks. I should have been clearer. Not only do I want to remove non-spacing characters, I also want to change accented letters to the corresponding unaccented letters. (This is for matching up foreign names... somebody long ago decided the database needed to be in plain ASCII

That is exactly what you achieve by first normalizing (using FormD) and then
removing nonspacing characters. The normalized string will contain an ascii
character followed by a non spacing modifier character which when combined
will be the original character. Remove the non spacing characters and all
that remains is the unaccented text.

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
21803
by: Darren Jensen | last post by:
Hi, Does anyone have a function which replaces accent chars from a string with the non-accented equivalent? For example 'hôpital' should return 'hopital'. Thank you in advance.
8
9257
by: Jan | last post by:
Hi there, Is there a way to remove spaces from a line of text? For example: vr 12-12-79 city village state name I want it to be:
36
2593
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): options { directory "/var/named"; listen-on { 192.168.11.22; 127.0.0.1; }; forwarders { 168.126.63.1; };
3
4857
by: YoungJohn | last post by:
I'm extracting data from a database to create a table. My table includes a text field 'Postcode' for postcodes. Sometimes the extracted postcodes are in the format SL37HY and in other instances a gap has been left somewhere in the data e.g. S L37HY or SL3 7HY. I want to validate the postcodes by matching them to a master table which contains postcodes in the format SL37HY i.e. no spaces.
2
2080
by: Gozil | last post by:
Hello, im having a problem with the text input field im working with. I've made an ajax application that will suggest different links below the input field but if the user already searched something before it will appear a suggest box with previous searches from that user... Look at the picture below and you'll understand what im talking about. http://img338.imageshack.us/img338/4500/preboxvk7.gif I have seen sites that never get that...
3
1352
by: ahd2008 | last post by:
HI, I created the code below to remove name from tex. For instance, a field contains Caffery(294643) so i want to get rid of Caffery and get only the figures, but the problme that the code gives this result: 294643) can anyone help to fixt it becasue i need only the figures. Private Sub Toggle2_Click()
4
1593
by: DetrieZ | last post by:
This is only removing the text characters.. I need it to remove all the text and everything after it Public Function ExtractNumeric(TextString As String) As String Dim x As Long Dim sDigit As String ExtractNumeric = vbNullString For x = 1 To Len(TextString)
4
20898
by: Nawaf Ali | last post by:
I am trying to do some text statistics, like word frequency, average word length, average sentence length, and average paragraph length, I managed to do the word frequency and the average sentence and word length. What I need to do next is preprocess the text file by removing some words, "listed in some other text file", and then do my statistics. And if some one can tell me how to do the average paragraph length too, please. Any help is...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.