字符串的特殊字符,反之亦然 [英] special character to strings and vice versa

查看:62
本文介绍了字符串的特殊字符,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正坐在一个问题上,我有一些特殊字符

已被字符串化意思是代替没有f。 X。 a''\ n''或

''\ x20'''我有'\ n"和\ x20而且我必须将它们转换回

普通字符(实际上能够将其反转)。现在我已经制作了一个

丑陋的开关声明来完成这项工作,但与此同时我觉得必须有一个更好的方法。是否有任何明显的遗漏?
错过了?


谢谢

彼得

解决方案



" Peter Monsson" < PE ********** @ yahoo.dk>在消息中写道

news:ac ************************** @ posting.google.c om ...

大家好,

我正坐在一个问题上,我有一些特殊字符,这些字符已被字符串化。意思是代替没有f。 X。 a''\ n''或
''\ x20''我有'\ n"和\ x20我必须将它们转换回
正常的char


char s [] =" \ x20 \ n";

char c1 = s [0];

char c2 = s [1];

(实际上能够将其反转)。现在我已经制作了一个丑陋的开关声明来完成这项工作,但与此同时我觉得必须有一个更好的方法。有没有明显的遗漏?




你错过了发布你的代码。


-Mike





Peter Monsson写道:

大家好,

我正坐在一个问题上,我有一些特殊字符,这些字符已被字符串化。意思是代替没有f。 X。 a''\ n''或
''\ x20''我有'\ n"和\ x20我必须将它们转换回
普通字符(实际上能够将其反转)。现在我已经制作了一个丑陋的开关声明来完成这项工作,但与此同时我觉得必须有一个更好的方法。有没有明显的遗漏?

谢谢
彼得




我不知道你是什​​么意思fx a。但是使用gets()可能是一个想法。

gets()返回一个char *。在char变量中分配返回值。

您可能已经在开关案例中尝试了上述方法。

但除非你发布一些代码,否则这个组的'br />
专家可能无法帮助你。


-

组合是国际象棋的核心

A.Alekhine

邮件:

sathyashrayan25雅虎DOT com

(AT = @和DOT =。)


2004年11月11日星期四09:29:35 + 0530,sathya< sa **** @ nomail.com>在comp.lang.c写了




Peter Monsson写道:


我正坐在一个问题上,我有一些特殊字符,这些字符已被字符串化。意思是代替没有f。 X。 a''\ n''或
''\ x20''我有'\ n"和\ x20我必须将它们转换回
普通字符(实际上能够将其反转)。现在我已经制作了一个丑陋的开关声明来完成这项工作,但与此同时我觉得必须有一个更好的方法。有什么明显的我已经错过了吗?

谢谢
彼得



我不知道你是什么意思通过fx a。但是使用gets()可能是一个想法。
gets()返回一个char *。在char变量中分配返回值。
您可能已经在开关案例中尝试了上述方法。
但除非您发布一些代码,否则该组的专家可能无法帮助你。




如果你不知道你到底是什么,请不要在这里发帖

谈论你,你最肯定不会在这种情况下。


1.永远不要,永远不要使用gets(),或推荐使用它。它是整个C标准库中最危险的功能,没有,

,因为绝对没有办法安全使用它。

2.即使不应该使用gets(),它确实会返回一个

指向字符的指针。建议指向角色的指针应该被分配给一个char是不好的建议,首先是因为它在这个(或几乎没有任何其他)上下文中没有意义

,第二个因为一个演员需要

,第三,因为在大多数情况下很可能会导致

未定义的行为。


-

Jack Klein

主页: http: //JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com / c ++ - faq-lite /

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Hi all,

I''m sitting with a problem where I have some special characters which
have been "stringified" meaning that instead of having f. x. a ''\n'' or
''\x20'' I have "\n" and "\x20" and I have to convert them back to a
normal char (and actually be able to revers this). Now I''ve made an
ugly switch statment to make this work, but at the same time I feel
that there must be a better way. Is there anything obvious I''ve
missed?

Thanks
Peter

解决方案


"Peter Monsson" <pe**********@yahoo.dk> wrote in message
news:ac**************************@posting.google.c om...

Hi all,

I''m sitting with a problem where I have some special characters which
have been "stringified" meaning that instead of having f. x. a ''\n'' or
''\x20'' I have "\n" and "\x20" and I have to convert them back to a
normal char
char s[] = "\x20\n";
char c1 = s[0];
char c2 = s[1];
(and actually be able to revers this). Now I''ve made an
ugly switch statment to make this work, but at the same time I feel
that there must be a better way. Is there anything obvious I''ve
missed?



You missed posting your code.

-Mike




Peter Monsson wrote:

Hi all,

I''m sitting with a problem where I have some special characters which
have been "stringified" meaning that instead of having f. x. a ''\n'' or
''\x20'' I have "\n" and "\x20" and I have to convert them back to a
normal char (and actually be able to revers this). Now I''ve made an
ugly switch statment to make this work, but at the same time I feel
that there must be a better way. Is there anything obvious I''ve
missed?

Thanks
Peter



I don''t know what do you mean by f.x a. But using gets() might be a idea.
gets() returns a char *. Assign the return value in a char variable.
You might have tried the above method in your switch case.
But unless you post some code this group''s
experts might not be able to help you.

--
"Combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan25 AT yahoo DOT com
(AT = @ and DOT = .)


On Thu, 11 Nov 2004 09:29:35 +0530, sathya <sa****@nomail.com> wrote
in comp.lang.c:



Peter Monsson wrote:

Hi all,

I''m sitting with a problem where I have some special characters which
have been "stringified" meaning that instead of having f. x. a ''\n'' or
''\x20'' I have "\n" and "\x20" and I have to convert them back to a
normal char (and actually be able to revers this). Now I''ve made an
ugly switch statment to make this work, but at the same time I feel
that there must be a better way. Is there anything obvious I''ve
missed?

Thanks
Peter



I don''t know what do you mean by f.x a. But using gets() might be a idea.
gets() returns a char *. Assign the return value in a char variable.
You might have tried the above method in your switch case.
But unless you post some code this group''s
experts might not be able to help you.



Please don''t post here if you do not know what the heck you are
talking about, and you most surely do not in this case.

1. Never, never, NEVER use gets(), or recommend its use. It is the
most dangerous function in the entire C standard library, bar none,
because there is absolutely no way to use it safely.

2. Even though gets() should NEVER be used, it does indeed return a
pointer to character. Suggesting that a pointer to character should
be assigned to a char is bad advice, first because it makes no sense
in this (or hardly any other) context, second because a cast is
required, and third because there is a good chance it will cause
undefined behavior in most cases.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于字符串的特殊字符,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆