Board index » cppbuilder » String to Char
Jeff
CBuilder Developer |
Jeff
CBuilder Developer |
String to Char2007-02-28 02:35:09 AM cppbuilder99 Anyone know how to convert a String to a single character? For instance, how do you convert the "\r" string to a '\r' character? |
Liz Albin
CBuilder Developer |
2007-02-28 02:59:53 AM
Re:String to Char
Jeff wrote:
QuoteFor instance, how do you convert the "\r" string to a '\r' c = s[0]; -- Liz Please check the newsgroup guidelines and general netiquette info.borland.com/newsgroups/guide.html info.borland.com/newsgroups/guide.html info.borland.com/newsgroups/netiquette.html |
Dennis Cote
CBuilder Developer |
2007-02-28 03:03:18 AM
Re:String to Char
Jeff wrote:
QuoteAnyone know how to convert a String to a single character? will return the first character of the string or a '\0' char if the string is empty. HTH Dennis Cote {smallsort} |
Jeff
CBuilder Developer |
2007-02-28 03:10:57 AM
Re:String to Char
I don't just want the first character of the string I need to translate the
"\r" string into the carriage return character. "Dennis Cote" < XXXX@XXXXX.COM >wrote in message QuoteJeff wrote: |
Ed Mulroy
CBuilder Developer |
2007-02-28 03:49:36 AM
Re:String to Char
The first character in that string IS the carriage return character.
char carriage_return = "\r"[0]; . Ed QuoteJeff wrote in message |
Dennis Jones
CBuilder Developer |
2007-02-28 03:56:21 AM
Re:String to Char
"Jeff" < XXXX@XXXXX.COM >wrote in message
QuoteI don't just want the first character of the string I need to translate the or an object of some string class that contains the text "\r". You also don't say whether or not the string is guaranteed to be one character in length, or if the '\r' occurs somewhere in the middle of some other string. Given the arbitrariness of your question, one could answer that: "\r"[0] and *"\r" will both yield '\r'. Perhaps you could provide a snippet that explains what you are trying to do? - Dennis |
Chris Uzdavinis
CBuilder Developer |
2007-02-28 04:14:56 AM
Re:String to Char
"Jeff" < XXXX@XXXXX.COM >writes:
QuoteI don't just want the first character of the string I need to translate the interpreted at compile time to be a single charcter. Now, if you mean you have 2 bytes in an array of characters, like this: char ary[] = {'\\', 'r'}; And you want to convert those 2 bytes into the '\r' character, you'll have to look at the first byte and decide if it's a backslash, and if so, read the next charcter and perform your own translation. If the first character is not a backslash, then you'd just use that. Is that what you're asking? -- Chris (TeamB); |
maeder
CBuilder Developer |
2007-02-28 05:37:46 AM
Re:String to Char
"Liz Albin" < XXXX@XXXXX.COM >writes:
I know that you know, Liz; just to avoid confusion: Quotechar c; Quotec = s[0]; |
Jeff
CBuilder Developer |
2007-02-28 05:58:45 AM
Re:String to Char
Yes that's what I wanted to confirm. Thanks for all the input.
"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message Quote"Jeff" < XXXX@XXXXX.COM >writes: |
Thorsten Kettner
CBuilder Developer |
2007-03-01 12:05:47 AM
Re:String to CharQuoteAnyone know how to convert a String to a single character? MyString = StringReplace(MyString, "\\r", "\r", TReplaceFlags() << rfReplaceAll); |