![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
from MID() in VB to Python?
do anyone know the equivalent of the function MID() in VB, for Python?
thx in advance...
__________________
I was born to catch dragons in their dens. And pick flowers. To tell tales and laugh away the morning. To drift and dream like a lazy stream And walk barefoot across sunshine days |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
Well, if you tell us, what the function does, i am pretty sure, that somebody can answer your qouestion...
|
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It takes a section of a string. In Python, this is built into the language:
str = This is a string.
01234567890123456You can take individual characters by typing the index in square brackets after the variable name: # str[1] = "h" # str[12] = "r" You can also take slices using the colon ( : ) operator - the first number is the index of the first letter; the second is the the index of the first letter after the end of the slice. # str[1:3] = "his" # str[12:17] = "ring." If you leave the slice open, it carries on until it hits the beginning or the end: # str[8:] = "a string." # str[:3] = "Thi" # str[:] = "This is a string." You can also use negative numbers to refer to characters from the end: # str[-2] = "g" # str[1:-2] = "his is a strin" Enjoy. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
You mean, that a normal assignment thingy like '=' is not built in in VB??
Woah, I always thought these would make the core of each language... Weird world |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
My dad tells me that MID, RIGHT and LEFT are holdovers from the old Mbasic. Python takes care of that with slicing.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Did you even read my post, Fred? I explained splicing, not assignment.
|
|
|
|
|
|
#7 | |
|
Newbie
|
Quote:
thx for this enlightment ![]()
__________________
I was born to catch dragons in their dens. And pick flowers. To tell tales and laugh away the morning. To drift and dream like a lazy stream And walk barefoot across sunshine days |
|
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I forgot to mention; you can also change slices (and you don't even have to stick to the same number of characters):
str[1:3] = "xyz" print str # str = "Txyzs is a string." |
|
|
|
|
|
#9 | |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
Quote:
![]() I thought you were talking about assignment, when you said, that it 'takes' a string, and the showed, what you could do with this datatype. |
|
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
Quote:
Type Error: object doesn't support slice assignment |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|