Re: String Character Conversion





Jayson Davis wrote On 06/30/06 12:43,:
Eric Sosman wrote:

Jayson Davis wrote On 06/30/06 11:46,:


Say I have a string read from a configuration file.

searchfor <tab> Needle\n\n

Where I want to search for the word "Needle" with two linefeeds. Now
when I read it from the file, it hasn't converted the linefeeds into
characters. Is there a function to do that or do I need to write it myself?


Please explain what you mean by "it hasn't converted ..."
The newline characters *are* characters, and can be read and
written just like vowels and consonants.



Thanks for the reply. I'm taking a summer course in C and this is all a
tad overwhelming having it shoved into such a short timespan.

The string as read is "Needle\n\n", but what the string really needs to
be is "Needle\x0A0\x0A" in order for strstr() or strcmp() to work. In
other words, the string is literal "\n" and not '\n'.

Aha! I think I may have (*may* have) figured out
your difficulty. When you say the string as read is
"Needle\n\n", do you mean that there are ten characters
before the zero, the last four of which are "backslash,
n, backslash, n?" And that what you want is an eight-
character string ending in "newline, newline?"

If so, then no: There is nothing in the Standard
library that duplicates the operation of the C compiler
in translating escape sequences to characters. Those
escape sequences are a convention used only (as far as
C itself is concerned) in C source code, and the special
handling given to them by the compiler is not part of
the run-time library.

Your program, it seems, wants to use a similar
convention to represent "difficult" characters. If
that's what you're after, you'll need to write your
own translation code. Depending on how many of the C
source forms you decide to accept, the size of this
project could be anywhere from trivial to smallish.

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: String Character Conversion
    ... Now when I read it from the file, it hasn't converted the linefeeds into characters. ... The string as read is "Needle\n\n", but what the string really needs to be is "Needle\x0A0\x0A" in order for strstror strcmpto work. ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
    (comp.programming)
  • Re: Byte Array to String
    ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
    (microsoft.public.dotnet.framework.aspnet)