[DGD]Adding character to string
Frantisek Fuka
fuxoft at terminal.cz
Fri Mar 30 01:30:43 CEST 2001
I have this problem with DGD 1.2. The solution is probably very simple
but I couldn't come up with anything elegant and it drives me mad.
I need to be able to get the character according to its ASCII number.
For example, if I have string str = "foo" and integer num = 65, i need
to somehow do (str + (char)num) and get "fooA", but I keep getting
"foo65" and I can find no function to convert 65 to "A". I know it can
be done by doing
str = "foo?"; str [3] = num; /* replaces '?' with 'A' */
but that seems cumbersome to me. Specifically, I need to use the
following function for translating all output from one character coding
to other so it has to be quick and elegant (it also adds '\x0D' before
each "\n" because i use binary port for output):
string out;
out = "";
for (i=0; i<strlen(msg); i++) {
if (msg[i] == '\n') out += '\x0D';
out += (msg[i] >= 128) ? charset_output[msg[i]-128] : msg[i];
}
Unfortunately, instead of character (for example 'A'), the string "65"
is being added to 'out' variable.
Any help is appreciated.
--
Frantisek Fuka
(yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")
----------------------------------------------------
My E-mail: fuxoft at terminal.cz
My Homepage: http://www.fuxoft.cz
My ICQ: 2745855
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list