hi all,
howto split string with both comma and semicolon delimiters?
i.e. (for example) get ['a','b','c'] from string "a,b;c"
I have tried s.split(',;') but it don't work
Thx, D. 4 10199
dmitrey wrote:
hi all,
howto split string with both comma and semicolon delimiters?
i.e. (for example) get ['a','b','c'] from string "a,b;c"
I have tried s.split(',;') but it don't work
Thx, D.
-- http://mail.python.org/mailman/listinfo/python-list
The regular expression module has a split function that does what you
want.
>>import re r =',|;' # or this also works: '[,;]' s = "a,b;c" re.split(r, s)
['a', 'b', 'c']
Gary Herron
howto split string with both comma and semicolon delimiters?
>
i.e. (for example) get ['a','b','c'] from string "a,b;c"
I have tried s.split(',;') but it don't work
A very pedestrian solution would be:
def multisplit( s, seps ):
words = [ ]
word = ''
for char in s:
if char in seps:
if word:
words.append( word )
word = ''
else:
word += char
if word:
words.append( word )
return words
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
dmitrey wrote:
hi all,
howto split string with both comma and semicolon delimiters?
i.e. (for example) get ['a','b','c'] from string "a,b;c"
I have tried s.split(',;') but it don't work
Thx, D.
Howabout :
s = s.replace(";", ",")
s = s.split(",")
On Jun 12, 8:06 pm, bvdp <b...@mellowood .cawrote:
dmitrey wrote:
hi all,
howto split string with both comma and semicolon delimiters?
i.e. (for example) get ['a','b','c'] from string "a,b;c"
I have tried s.split(',;') but it don't work
Thx, D.
Howabout:
s = s.replace(";", ",")
s = s.split(",")
I've wondered in the past whether there would be sufficient need for
things like s.split((',', ';')) and s.partition((', ', ';')). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: William Stacey [MVP] |
last post by:
Would like help with a (I think) a common regex split example. Thanks for
your example in advance. Cheers!
Source Data Example:
one "two three" four
Optional, but would also like to ignore pairs of brackets like:
"one" <tab> "two three" ( four "five six" )
Want fields like:
|
by: Senthil |
last post by:
Code
----------------------
string Line = "\"A\",\"B\",\"C\",\"D\"";
string Line2 = Line.Replace("\",\"","\"\",\"\"");
string CSVColumns = Line2.Split("\",\"".ToCharArray());
|
by: mannyGonzales |
last post by:
Hey guys,
Earliery I posted this common task of reading a csv file.
My data read as: "1","2","3"
Unfortunately it now reads as:
"1","Text with, comma", "2"
embedded commas!
--------------------------------------------
|
by: Ben |
last post by:
Hi
I am creating a dynamic function to return a two dimensional array from a
delimeted string.
The delimited string is like:
field1...field2...field3...
field1...field2...field3...
field1...field2...field3...
|
by: kurt sune |
last post by:
The code:
Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" &
vbNewLine
Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf)
Dim csvColumns2 As String() = Microsoft.VisualBasic.Strings.Split(aLine,
vbNewLine, -1, CompareMethod.Binary)
| |
by: lgbjr |
last post by:
Hi All,
I'm trying to split a string on every character. The string happens to be a
representation of a hex number. So, my regex expression is ().
Seems simple, but for some reason, I'm not getting the results I expect.
Dim SA as string()
Dim S as string
S="FBE"
|
by: tom t/LA |
last post by:
Here is a function to convert a CSV file to a Javascript array. Uses
idealized file reading functions based on the std C library, since
there is no Javascript standard. Not fully tested.
function csvToArray (f /* file handle */)
{
// convert csv file to Javascript 2d array (array of arrays)
// written in Javascript but file lib functions...
|
by: Tem |
last post by:
What would be the best way to split a string into a string array. with the
following possible inputs?
abc1 abc2 abc3 -single space
abc1 abc2 abc3 -multiple spaces
abc1,abc2,abc3 -comma
abc1, abc2, abc3 -comma + space
abc1;abc2;abc3 -semicolon
abc1; abc2; abc3 -semicolon + space
|
by: teddyber |
last post by:
Hello,
first i'm a newbie to python (but i searched the Internet i swear).
i'm looking for some way to split up a string into a list of pairs
'key=value'. This code should be able to handle this particular
example string :
qop="auth,auth-int,auth-conf",cipher="rc4-40,rc4-56,rc4,des,
3des",maxbuf=1024,charset=utf-8,algorithm=md5-sess
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |