Compare language special character
In other languages no English it is common to have a special character such as ñ in Spanish.
I have recently found myself wondering how can you compare two char such temporal == 'ñ'? Or temporal == char(-94) I have tried both and no one looks like working
c++
|
show 6 more comments
In other languages no English it is common to have a special character such as ñ in Spanish.
I have recently found myself wondering how can you compare two char such temporal == 'ñ'? Or temporal == char(-94) I have tried both and no one looks like working
c++
2
Thechar
type can besigned
,unsigned
orchar
. Ifsigned
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".
– Thomas Matthews
Nov 29 '18 at 0:48
4
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.
– zzxyz
Nov 29 '18 at 0:50
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49
|
show 6 more comments
In other languages no English it is common to have a special character such as ñ in Spanish.
I have recently found myself wondering how can you compare two char such temporal == 'ñ'? Or temporal == char(-94) I have tried both and no one looks like working
c++
In other languages no English it is common to have a special character such as ñ in Spanish.
I have recently found myself wondering how can you compare two char such temporal == 'ñ'? Or temporal == char(-94) I have tried both and no one looks like working
c++
c++
edited Nov 29 '18 at 4:51
GYaN
2,09731432
2,09731432
asked Nov 29 '18 at 0:27
YunhaoYunhao
136
136
2
Thechar
type can besigned
,unsigned
orchar
. Ifsigned
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".
– Thomas Matthews
Nov 29 '18 at 0:48
4
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.
– zzxyz
Nov 29 '18 at 0:50
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49
|
show 6 more comments
2
Thechar
type can besigned
,unsigned
orchar
. Ifsigned
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".
– Thomas Matthews
Nov 29 '18 at 0:48
4
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.
– zzxyz
Nov 29 '18 at 0:50
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49
2
2
The
char
type can be signed
, unsigned
or char
. If signed
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".– Thomas Matthews
Nov 29 '18 at 0:48
The
char
type can be signed
, unsigned
or char
. If signed
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".– Thomas Matthews
Nov 29 '18 at 0:48
4
4
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also
164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.– zzxyz
Nov 29 '18 at 0:50
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also
164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.– zzxyz
Nov 29 '18 at 0:50
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49
|
show 6 more comments
1 Answer
1
active
oldest
votes
I figure your most likely scenario is you get to choose the character set, and you have a console app. If not, the only thing you'll want to pay attention to is the first sentence, and the L
in front of strings in the code. And wchar_t
being your character type..
Make sure the project properties under General
are set to "Use Unicode Character Set". And also I'd forgotten a little trick with console apps. You have to set the console mode to unicode for some bizarre reason (probably backward compatibility). With UI apps, this is a non-issue.
#include <fcntl.h>
#include <io.h>
...
_setmode(_fileno(stdout), _O_U16TEXT); //use utf-16, like every other Windows system defaults to
_setmode(_fileno(stdin), _O_U16TEXT);
wchar_t n = 0x00f1; //see https://www.fileformat.info/info/charset/UTF-16/list.htm
_tprintf(L"%cn", n); //(or use wprintf explicitly)
_tprintf(L"ññññññññññn");
wcout << L"ñn";
I hope this is at least a little helpful.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53530123%2fcompare-language-special-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I figure your most likely scenario is you get to choose the character set, and you have a console app. If not, the only thing you'll want to pay attention to is the first sentence, and the L
in front of strings in the code. And wchar_t
being your character type..
Make sure the project properties under General
are set to "Use Unicode Character Set". And also I'd forgotten a little trick with console apps. You have to set the console mode to unicode for some bizarre reason (probably backward compatibility). With UI apps, this is a non-issue.
#include <fcntl.h>
#include <io.h>
...
_setmode(_fileno(stdout), _O_U16TEXT); //use utf-16, like every other Windows system defaults to
_setmode(_fileno(stdin), _O_U16TEXT);
wchar_t n = 0x00f1; //see https://www.fileformat.info/info/charset/UTF-16/list.htm
_tprintf(L"%cn", n); //(or use wprintf explicitly)
_tprintf(L"ññññññññññn");
wcout << L"ñn";
I hope this is at least a little helpful.
add a comment |
I figure your most likely scenario is you get to choose the character set, and you have a console app. If not, the only thing you'll want to pay attention to is the first sentence, and the L
in front of strings in the code. And wchar_t
being your character type..
Make sure the project properties under General
are set to "Use Unicode Character Set". And also I'd forgotten a little trick with console apps. You have to set the console mode to unicode for some bizarre reason (probably backward compatibility). With UI apps, this is a non-issue.
#include <fcntl.h>
#include <io.h>
...
_setmode(_fileno(stdout), _O_U16TEXT); //use utf-16, like every other Windows system defaults to
_setmode(_fileno(stdin), _O_U16TEXT);
wchar_t n = 0x00f1; //see https://www.fileformat.info/info/charset/UTF-16/list.htm
_tprintf(L"%cn", n); //(or use wprintf explicitly)
_tprintf(L"ññññññññññn");
wcout << L"ñn";
I hope this is at least a little helpful.
add a comment |
I figure your most likely scenario is you get to choose the character set, and you have a console app. If not, the only thing you'll want to pay attention to is the first sentence, and the L
in front of strings in the code. And wchar_t
being your character type..
Make sure the project properties under General
are set to "Use Unicode Character Set". And also I'd forgotten a little trick with console apps. You have to set the console mode to unicode for some bizarre reason (probably backward compatibility). With UI apps, this is a non-issue.
#include <fcntl.h>
#include <io.h>
...
_setmode(_fileno(stdout), _O_U16TEXT); //use utf-16, like every other Windows system defaults to
_setmode(_fileno(stdin), _O_U16TEXT);
wchar_t n = 0x00f1; //see https://www.fileformat.info/info/charset/UTF-16/list.htm
_tprintf(L"%cn", n); //(or use wprintf explicitly)
_tprintf(L"ññññññññññn");
wcout << L"ñn";
I hope this is at least a little helpful.
I figure your most likely scenario is you get to choose the character set, and you have a console app. If not, the only thing you'll want to pay attention to is the first sentence, and the L
in front of strings in the code. And wchar_t
being your character type..
Make sure the project properties under General
are set to "Use Unicode Character Set". And also I'd forgotten a little trick with console apps. You have to set the console mode to unicode for some bizarre reason (probably backward compatibility). With UI apps, this is a non-issue.
#include <fcntl.h>
#include <io.h>
...
_setmode(_fileno(stdout), _O_U16TEXT); //use utf-16, like every other Windows system defaults to
_setmode(_fileno(stdin), _O_U16TEXT);
wchar_t n = 0x00f1; //see https://www.fileformat.info/info/charset/UTF-16/list.htm
_tprintf(L"%cn", n); //(or use wprintf explicitly)
_tprintf(L"ññññññññññn");
wcout << L"ñn";
I hope this is at least a little helpful.
answered Dec 3 '18 at 20:17
zzxyzzzxyz
2,2291725
2,2291725
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53530123%2fcompare-language-special-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The
char
type can besigned
,unsigned
orchar
. Ifsigned
, there may not be enough range for special characters. You may need to invest in wide characters or 16-bit values to represent the characters. Search the internet for "c++ wide characters" or "c++ multibyte characters".– Thomas Matthews
Nov 29 '18 at 0:48
4
With ñ you need to understand what character set you're using. Likely one of these en.wikipedia.org/wiki/%C3%91 . Some representations of it take up two bytes. There's also
164
in the old "standard" extended ascii table, which is no longer standard, if it ever was, and there's "code pages" which replace it but have also fallen out of favor.– zzxyz
Nov 29 '18 at 0:50
Why do you need to compare individual characters, or in general access individual characters of a string? It is almost never needed for non-text-processing applications. There is nothing special in these characters BTW.
– n.m.
Nov 29 '18 at 4:54
i need to process a spanish text, and implements a letter counter
– Yunhao
Nov 29 '18 at 10:49
Is this a school assignment? You should know that in Unicode accented characters can be represented in more than one way. First, as a letter followed by a separate combining accent character; and second, as a single pre-composed accented character. (Each character may occupy more than one byte). This may or may not be relevant for letter count, but it may break your word count if you are not careful.
– n.m.
Nov 29 '18 at 12:49