Hi,
are there a strtok equivalent in python ? str.split() only takes single
seperator. 2 7713 bo****@gmail.com wrote: are there a strtok equivalent in python ? str.split() only takes single seperator.
use a regular expression split with a character group: s = "breakfast=spam+egg-bacon" import re re.split("[-+=]", s)
['breakfast', 'spam', 'egg', 'bacon']
to deal with an arbitrary set of delimiting characters without having to
bother with RE syntax, use re.escape:
re.split("[" + re.escape("-+=") + "]", s)
['breakfast', 'spam', 'egg', 'bacon']
</F>
thanks.
Fredrik Lundh wrote: bo****@gmail.com wrote:
are there a strtok equivalent in python ? str.split() only takes single seperator.
use a regular expression split with a character group:
>>> s = "breakfast=spam+egg-bacon" >>> import re >>> re.split("[-+=]", s) ['breakfast', 'spam', 'egg', 'bacon']
to deal with an arbitrary set of delimiting characters without having to bother with RE syntax, use re.escape: >>> re.split("[" + re.escape("-+=") + "]", s)
['breakfast', 'spam', 'egg', 'bacon']
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ern |
last post by:
I'm using strtok( ) to capture lines of input. After I call
"splitCommand", I call strtok( ) again to get the next line. Strtok( )
returns NULL (but there is more in the file...). That didn't...
|
by: bubunia2000 |
last post by:
Hi all,
I heard that strtok is not thread safe. So I want to write a
sample program which will tokenize string without using strtok.
Can I get a sample source code for the same.
For exp:...
|
by: hu |
last post by:
hi, everybody!
I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0.
Program is simple, but mistake is confusing. First, the below code can get
right outcome:"ello world, hello...
|
by: Michael |
last post by:
Hi,
I have a proble I don't understand when using strtok(). It seems that if I
make a call to strtok(), then make a call to another function that also
makes use of strtok(), the original call is...
|
by: nomad5000 |
last post by:
Hi everybody!
I'm having trouble using strtok to fill a matrix with int nrs. from a file.
the code that is not working is the following:
#include <iostream>
#include <fstream>
#include...
|
by: Pietro Cerutti |
last post by:
Hello,
here I have a strange problem with a real simple strtok example.
The program is as follows:
### BEGIN STRTOK ###
#include <string.h>
#include <stdio.h>
|
by: Lothar Behrens |
last post by:
Hi,
I have selected strtok to be used in my string replacement function.
But I lost the last token, if there is one.
This string would be replaced
select "name", "vorname", "userid",...
|
by: magicman |
last post by:
can anyone point me out to its implementation in C before I roll my
own.
thx
|
by: Pilcrow |
last post by:
Here is a quick program, together with its output, that illustrates what
I consider to be a deficiency of the standard function strtok from
<string.h>:
I am using
C:\>gcc --version
gcc (GCC)...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |