Re: Interating over the characters in a string

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 15:24:35 +0300

Hi,

Use the System.Globalization.StringInfo class to iterate over Unicode
characters.

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"Carlo Razzeto" <crazzeto@hotmail.com> wrote in message
news:eJSZrWWoEHA.1308@TK2MSFTNGP14.phx.gbl...
> 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

  • Re: Defacto standard string library
    ... Is there a defacto standard string library ... Unicode, encoded in UTF8 format, except that a zero byte is ... Standard C string functions will be fine with this ... result, it cannot be encoded using a single byte per character, unless ...
    (comp.lang.c)
  • Re: Determining if a string is Unicode
    ... there's nothing magic about Unicode. ... where each character occupies 2 bytes, as opposed to a Single-Byte Character ... You could load up a string with rubbish, ... > INF file like so: ...
    (microsoft.public.vb.general.discussion)
  • Re: Determining if a string is Unicode
    ... bytes per character, and MULTI-byte occupies one!!?? ... there's nothing magic about Unicode. ... You could load up a string with rubbish, ... if I read in the INF file from a 9x based computer the string does ...
    (microsoft.public.vb.general.discussion)
  • Re: Arabic or Chinese characters in a URL link give error copying
    ... the active ANSI character set, ... Arabic/Chinese then the associated "wide" Unicode characters will have been ... Function ContainsWideChars(ByRef inString As String) As Boolean ... Dim iCh As Integer ...
    (microsoft.public.vb.general.discussion)
  • Re: Arabic characters gives ASCII code 63
    ... The only problem is that you are looking at the ASCII/ANSI values i.e. assuming that each character is represented as a number between 0 and 255. ... This is hidden from the developer - the length of a 5 character string is still 5 but it's still 10 bytes. ... all you need to do is get the unicode value for each character rather than the ANSI number. ... Dim CellValue As String ...
    (microsoft.public.excel.programming)