Pacific-Design.com

    
Home Index

1. Python

2. 01 String

Python / 01 String /

String

#!/usr/bin/python
#--------------------------------------------------------#
class MyString:

    def parse_string(self, line):

        words = line.split()
        array = []
        for word in words:
            # array.append(word.strip('\n\r\t'))
            array.append(word)

        for element in array:
            print element


#--------------------------------------------------------#
a = 'String Parsing Transformation'
print 'String: {}'.format(a)
print "-" * 40

str = '''\
Kevin
Thomas
Duraj
'''

string1 = MyString()
string1.parse_string(str)
print(type(str))

print "-" * 40
string2 = MyString()
string2.parse_string("kevin thomas duraj")

String: String Parsing Transformation ---------------------------------------- Kevin Thomas Duraj <type 'str'> ---------------------------------------- kevin thomas duraj

Reference: