[Tutor] trying to find the python equivalent for VB6 "left",
"right" and "mid"
McLaughlin, Toby
tmclaughlin at csu.edu.au
Mon Nov 22 02:50:29 CET 2004
Hello Fabian,
What you are looking for is Python "slicing". You can choose any subset
of a sequence with slicing.
Example:
>>> mystring = "Hello world"
>>> print mystring[0:7]
Hello w
>>> print mystring[1:9]
ello wor
>>>
Note that the offsets are different to the ones you used in VB. I found
this strange at first. The numbers specify where in the sequence to
make a "cut". Here's a diagram:
Elements: [H] [e] [l] [l] [o] [ ] [w] [o] [r] [l] [d]
Indices: 0 1 2 3 4 5 6 7 8 9 10
Hope that helps,
Toby McLaughlin.
> -----Original Message-----
> From: tutor-bounces at python.org
> [mailto:tutor-bounces at python.org] On Behalf Of Fabian von Berlepsch
> Sent: Monday, 22 November 2004 12:29 PM
> To: tutor at python.org
> Subject: [Tutor] trying to find the python equivalent for VB6
> "left","right" and "mid"
>
>
> Hallo Guys,
>
> I am almost having a nerve crisis!
> Since 3 hours I am trying to find the python equivalent for
> VB6 "left",
> "right" and "mid".
>
> Example (what I am looking for):
>
> >>> mystring = "Hello world"
>
> >>> print left(mystring,7)
>
> Hello w
>
> - or -
>
> >>> mystring = "Hello world"
>
> >>> print mid(mystring,2,8)
>
> ello wor
>
> --------------------------
>
> You see?
> Thank you so much for getting me out of that mess!
>
> Fabian
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list