Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Aug 23rd, 2005, 6:27 AM   #1
acidrock
Newbie
 
Join Date: Aug 2005
Posts: 2
Rep Power: 0 acidrock is on a distinguished road
I'm a new to Python

Hey guys, nice forums you have here.
Anyway I've started to learn python, today infact, as I've heard its a good language to learn, I have some experience in BASIC and a little in C from using Linux. I was wondering if there was a function in Python that did the same as mid$() in BASIC, I've searched for tutorials on string manipulation etc, but could not find anything on this function.
Thanks.

Last edited by acidrock; Aug 23rd, 2005 at 6:48 AM.
acidrock is offline   Reply With Quote
Old Aug 23rd, 2005, 6:49 AM   #2
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
I have no experiance in BASIC, so please explain what the mid$() function does, then i can help you out.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Aug 23rd, 2005, 6:55 AM   #3
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Ok, i searched google and i didn't find much, from what i found i think that mid$() finds the length of a string.

In Python we have the len() function.
Example 1
>>> len("hello")
5
Example 2:
>>> variable = "hello"
>>>len(variable)
5
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Aug 23rd, 2005, 8:32 AM   #4
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
I think the mid function returns a part of a string. In python, you can consider a string as a list of characters and use the [] notation to get slices. See this tutorial on Python string handling or some simple code:
>>> s = "Hello World!"
>>> s[0]
'H'
>>> s[0:5]
'Hello'
>>> s[:5]
'Hello'
>>> s[6:13]
'World!'
>>> s[6:]
'World!'
>>> s[-1]
'!'
Moldz is offline   Reply With Quote
Old Aug 23rd, 2005, 12:16 PM   #5
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by coldDeath
I have no experiance in BASIC, so please explain what the mid$() function does, then i can help you out.
SubStr$ = MID$(MainStr$, Start% [, Length%])

returns a substring of a string
SubStr$ = MID$("abcdefg",3,4)
' Result: SubStr$ will equal "cdef"

SubStr$ = MID$("abcdefg",2)
' Result: SubStr$ will equal "bcdefg"
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Aug 23rd, 2005, 12:27 PM   #6
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Ok, so my examples are correct to what he wants.
Thanks Dietrich for clearing that up.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Aug 23rd, 2005, 4:00 PM   #7
acidrock
Newbie
 
Join Date: Aug 2005
Posts: 2
Rep Power: 0 acidrock is on a distinguished road
That's helped alot, thanks guys.
acidrock 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 2:48 AM.

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