I have strings like this 'some-dasd\dasd-dasdas\dasdas-dasd-das\dsad
'.
I need to split the string to array by two different symbols '\'
and '-'
, so I would like to get the array ['some', 'dasd', 'dasd', 'dasdas', 'dasdas', 'dasd', 'das' ,'dsad']
.
What is the best way to do it?
To split a string with multiple delimiters: Use the str. replace() method to replace the first delimiter with the second. Use the str. split() method to split the string by the second delimiter.
split() method accepts two arguments. The first optional argument is separator , which specifies what kind of separator to use for splitting the string. If this argument is not provided, the default value is any whitespace, meaning the string will split whenever .
Using the STUFF & FOR XML PATH function we can derive the input string lists into an XML format based on delimiter lists. And finally we can load the data into the temp table..
Split the string with multiple separatorsWe can also specify multiple characters as separators. For this, we need to make use of the re module of Python and import the re. split() function.
"ome-dasd\dasd-dasdas\dasdas-dasd-das\dsad".split(/\\|-/)
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With