![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 13
Rep Power: 0
![]() |
string split_once() function?
Hi,
Is there some easy way to split a string by the first occurance of a certain character to make two strings? If I use sentence = "What is your quest?"
partOne, partTwo = sentence.split_once(' ')partOne = "What" partTwo = "is your quest?" I've been using things like parts = []
parts = sentence.split(' ')
partOne = parts[0] |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
The split function has options like s.split([ separator[, maxsplit]]):
sentence = "What is your quest?"
partOne, partTwo = sentence.split(' ', 1)
print partOne, partTwo
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2006
Posts: 13
Rep Power: 0
![]() |
Perfect. Thanks.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|