Interating over the characters in a string

From: Carlo Razzeto (crazzeto_at_hotmail.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 08:05:50 -0400

Hello, I have a question in regards to .Net string maniplulation. I have a
question in regards to interating over individual characters in a string.
The problem is I have a CSV parser that will successfully parse out quoted
csv files, the only issue is it will leave the leading and ending quotes in
tact. Before I go on I do realize since it's a CSV I could do
stringval.replace( "\"", "" ); but I wanted to take the chance to learn out
to iterate over string values. Anyway, the problem is what I had written
originally to do this was:

if ( stringval[0] == '"' ) {
    stringval = stringval.substring( 1, ( stringval.length - 1 ) );
}
if( stringval[( stringval.length - 1 )] == '"' ) {
    stringval = stringval.substring( 0, ( stringval.length - 2 ) );
}

I wasn't stripping off the last " ever and I realize now that the problem
has to do with .Net storing strings in UNICODE, which allows for character
pairs to reprisent a single character. So my question here is, how does one
iterate over the character values in a string and replace it's value if
neccessary?

Carlo



Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)
  • Re: A note on computing thugs and coding bums
    ... code is valid for any character set that is legal in C (which is a ... characters in the required source character set ... A String, in C Sharp or Java, can be redefined. ... allow programmers to handle some other data format, ...
    (comp.programming)

Quantcast