[Haskell-beginners] Re: Iterating through a list of char...

Hein Hundal hundalhh at yahoo.com
Thu Apr 29 08:46:14 EDT 2010


Jean-Nicolas,

   Here is a variation on Corentin's solution:

-- This function replaces every character that 
-- follows an 'a' with 'A'

repA :: String -> String

repA s = zipWith f (' ':s) s where
   f 'a' y = 'A'
   f  x  y =  y 

Cheers,
Hein


> From: Jean-Nicolas Jolivet <jeannicolascocoa at gmail.com>
>
> I'm trying to iterate through each character of a string
> (that part I
> can do!) however, I need to apply a transformation to each
> character...based on the previous character in the string!
> This is the part I have no clue how to do!
> [snip]
> while i < my_string length:
>     if my_string[i-1] == some_char:
>         do something with
> my_string[i]
>     else
>         do something else
> with my_string[i]



      


More information about the Beginners mailing list