Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 10th, 2005, 10:38 AM   #1
saragonhat
Newbie
 
saragonhat's Avatar
 
Join Date: Feb 2005
Posts: 9
Rep Power: 0 saragonhat is on a distinguished road
Send a message via Yahoo to saragonhat
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
saragonhat is offline   Reply With Quote
Old Mar 10th, 2005, 3:40 PM   #2
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Well, if you tell us, what the function does, i am pretty sure, that somebody can answer your qouestion...
Fred is offline   Reply With Quote
Old Mar 10th, 2005, 5:55 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It takes a section of a string. In Python, this is built into the language:
str = This is a string.
      01234567890123456

You 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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 10th, 2005, 7:44 PM   #4
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
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
Fred is offline   Reply With Quote
Old Mar 11th, 2005, 12:20 AM   #5
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

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!
Dietrich is offline   Reply With Quote
Old Mar 11th, 2005, 10:54 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Did you even read my post, Fred? I explained splicing, not assignment.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 11th, 2005, 11:18 AM   #7
saragonhat
Newbie
 
saragonhat's Avatar
 
Join Date: Feb 2005
Posts: 9
Rep Power: 0 saragonhat is on a distinguished road
Send a message via Yahoo to saragonhat
Quote:
Originally Posted by Ooble
It takes a section of a string. In Python, this is built into the language:
str = This is a string.
      01234567890123456

You 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.

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
saragonhat is offline   Reply With Quote
Old Mar 11th, 2005, 3:39 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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."
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 11th, 2005, 3:41 PM   #9
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Quote:
Originally Posted by Ooble
Did you even read my post, Fred? I explained splicing, not assignment.
Read and misunderstood...
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.
Fred is offline   Reply With Quote
Old Mar 11th, 2005, 3:46 PM   #10
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Quote:
Originally Posted by Ooble
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."
If you are talking about normal strings, the you cannot. They do not support slice replacement. Gives the following error:
Type Error: object doesn't support slice assignment
All other slice thingies work though.
Fred is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC