Convert string to char array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brandon

    Convert string to char array

    How do I convert a string to a char array? I am doing this so I can edit
    the string received from an sql query so I can remove unnecessary
    characters.


  • Larry Bates

    #2
    Re: Convert string to char array

    Brandon wrote:
    How do I convert a string to a char array? I am doing this so I can edit
    the string received from an sql query so I can remove unnecessary
    characters.
    >
    >
    The precise answer is:
    >>s = 'abcdefghi'
    >>l = list(s)
    >>l
    ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
    >>>
    But quite often you can just to the replace without doing the conversion
    >>s = 'abc,de,fghi'
    >>s2 = s.replace(',',' ')
    >>s2 = s.replace(',',' ')
    'abcdefghi'
    >>>
    -Larry

    Comment

    • Mike Kent

      #3
      Re: Convert string to char array

      On Jul 1, 2:49 pm, "Brandon" <deanfamil...@v erizon.netwrote :
      How do I convert a string to a char array?  I am doing this so I can edit
      the string received from an sql query so I can remove unnecessary
      characters.
      Answering your specific question:

      Python 2.5.1 (r251:54863, Mar 31 2008, 11:09:52)
      [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
      Type "help", "copyright" , "credits" or "license" for more information.
      >>s = 'hello'
      >>l = list(s)
      >>l
      ['h', 'e', 'l', 'l', 'o']
      >>>
      But more generally, you might want to read up on the string methods
      available to you, such as replace():

      Comment

      • Brandon

        #4
        Re: Convert string to char array

        Thank you both for your help.

        "Mike Kent" <mrmakent@cox.n etwrote in message
        news:4670347e-2531-4449-a171-e352e1053864@r6 6g2000hsg.googl egroups.com...
        On Jul 1, 2:49 pm, "Brandon" <deanfamil...@v erizon.netwrote :
        How do I convert a string to a char array? I am doing this so I can edit
        the string received from an sql query so I can remove unnecessary
        characters.
        Answering your specific question:

        Python 2.5.1 (r251:54863, Mar 31 2008, 11:09:52)
        [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
        Type "help", "copyright" , "credits" or "license" for more information.
        >>s = 'hello'
        >>l = list(s)
        >>l
        ['h', 'e', 'l', 'l', 'o']
        >>>
        But more generally, you might want to read up on the string methods
        available to you, such as replace():



        Comment

        Working...