473,503 Members | 2,120 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 9883

"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 normalizedString = regularString.Normalize(NormalizationForm.FormD);

StringBuilder sb = new StringBuilder(normalizedString);

for (int i = 0; i < sb.Length; i++)
{
if (CharUnicodeInfo.GetUnicodeCategory(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.edu.slash.mcwrote in message
news:%2****************@TK2MSFTNGP04.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
21785
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
9249
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
2565
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): ...
3
4826
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...
2
2059
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...
3
1337
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...
4
1583
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...
4
20845
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...
0
7204
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,...
0
7282
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,...
1
6998
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...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4680
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...
0
1516
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 ...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
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...

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.