www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Replacing hex values in a string (v1.0)

reply jicman <cabrera_ _wrc.xerox.com> writes:
Greetings and salutations.

Hi.  I am reading a file into a string,

char[] text = cast(string) f0.read();

and I want to replace every non-breaking space in the string.  I know that the
hex value for that is A0, but when I do this call,

text = std.string.replace(text,x"A0"," ");

It does takes it out, but it adds (or leaves) a little square to it. 
Apparently, it leaves something else, there.  It would be nice if std.string
had a function to go from hex to decimal and back.

Any ideas?

thanks,

josé
Aug 12 2011
parent reply torhu <no spam.invalid> writes:
On 12.08.2011 18:19, jicman wrote:
 Greetings and salutations.

 Hi.  I am reading a file into a string,

 char[] text = cast(string) f0.read();

 and I want to replace every non-breaking space in the string.  I know that the
hex value for that is A0, but when I do this call,

 text = std.string.replace(text,x"A0"," ");

 It does takes it out, but it adds (or leaves) a little square to it. 
Apparently, it leaves something else, there.  It would be nice if std.string
had a function to go from hex to decimal and back.

 Any ideas?
Is the file UTF-8? In that case, try "\u00A0" instead, as "A0" won't be correct then.
Aug 12 2011
parent jicman <cabrera_ _wrc.xerox.com> writes:
torhu Wrote:

 On 12.08.2011 18:19, jicman wrote:
 Greetings and salutations.

 Hi.  I am reading a file into a string,

 char[] text = cast(string) f0.read();

 and I want to replace every non-breaking space in the string.  I know that the
hex value for that is A0, but when I do this call,

 text = std.string.replace(text,x"A0"," ");

 It does takes it out, but it adds (or leaves) a little square to it. 
Apparently, it leaves something else, there.  It would be nice if std.string
had a function to go from hex to decimal and back.

 Any ideas?
Is the file UTF-8? In that case, try "\u00A0" instead, as "A0" won't be correct then.
Thanks, that works. josé
Aug 12 2011