Re: Interating over the characters in a string

From: Richard Blewett [DevelopMentor] (richardb_at_develop.com)
Date: 09/23/04


To: microsoft.public.dotnet.framework
Date: Thu, 23 Sep 2004 05:23:25 -0700

Does this demonstrate what you want to do?

 using System;
 using System.Text;

 class App
 {
     static void Main(string[] args)
     {
         string s = "\"hello\",\"world\",\"the\",\"quick\",\"brown\",\"fox\"";

         string[] bits = s.Split(new char[]{'\"', ','});
         Console.WriteLine(s);

         StringBuilder sb = new StringBuilder();
   
         foreach( string b in bits )
         {
             if( b.Length!= 0 )
             {
                 Console.WriteLine(b);
                 sb.Append(b);
             }
         }

         Console.WriteLine(sb.ToString());
     }
 }

 Regards

 Richard Blewett - DevelopMentor
 http://staff.develop.com/richardb/weblog

   nntp://news.microsoft.com/microsoft.public.dotnet.framework/>

 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
 
 
 
 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (
http://www.grisoft.com).
 Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

 
 [microsoft.public.dotnet.framework]



Relevant Pages

  • Re: how can i change the text delimiter
    ... we receive the data in csv format ... ... Defines the character used to quote fields that ... Defines the character that will be used to separate ... Extracts fields from the CSV record in string. ...
    (comp.lang.python)
  • Re: Interating over the characters in a string
    ... double-quote character can be embedded within a string. ... Also, commas can occur in the quoted string too, so Splitmay not work ... >> The problem is I have a CSV parser that will successfully parse out ... > Although Unicode allows surrogate pairs, ...
    (microsoft.public.dotnet.framework)
  • Re: how to convert xf0 to 0xf0 ?
    ... various lengths into the appropriate Python types, ... directly, but in python, it is a string. ... because the actual character is not printable: ...
    (comp.lang.python)
  • Interating over the characters in a string
    ... I have a question in regards to .Net string maniplulation. ... pairs to reprisent a single character. ...
    (microsoft.public.dotnet.framework)
  • Re: Arrays of pointers to strings?
    ... Best regards ... "Joe" wrote: ... This displays the first character of every string: ... What if I wanted to display the 3rd character of every string instead? ...
    (microsoft.public.vc.language)