Strings for a newbie
Kalle Anka
skromta at gmail.com
Fri May 27 09:52:56 EDT 2005
Malcolm Wooden <mwooden <at> dtptypes.com> writes:
> I want to put a sentence of words into an array, eg "This is a sentence of
> words"
>
> In RB it would be simple:
>
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
>
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
> a.append NthField(s," ",i)
> next
>
> That's it an array a() containing the words of the sentence.
>
> Now can I see how this is done in Python? - nope!
Compare this RB code
dim s as String
dim a(-1) as String
s = "This is a sentence of words"
a = s.split()
with the python code
>>> s = "This is a sentece of words"
>>> s.split()
['This', 'is', 'a', 'sentece', 'of', 'words']
>>>
More information about the Python-list
mailing list