split

python split a string with at least 2 whitespaces

不羁岁月 提交于 2020-04-18 06:12:43
问题 I would like to split a string only where there are at least two or more whitespaces. For example str = '10DEUTSCH GGS Neue Heide 25-27 Wahn-Heide -1 -1' print str.split() Results: ['10DEUTSCH', 'GGS', 'Neue', 'Heide', '25-27', 'Wahn-Heide', '-1', '-1'] I would like it to look like this: ['10DEUTSCH', 'GGS Neue Heide 25-27', 'Wahn-Heide', '-1', '-1'] 回答1: In [4]: import re In [5]: text = '10DEUTSCH GGS Neue Heide 25-27 Wahn-Heide -1 -1' In [7]: re.split(r'\s{2,}', text) Out[7]: ['10DEUTSCH',

Split a vector into equal length of subvectors with a leftover as the last subvector when the length is not divisible with its subset [duplicate]

这一生的挚爱 提交于 2020-04-12 07:28:40
问题 This question already has answers here : Split a vector into chunks in R (20 answers) Closed 7 months ago . I want to split a vector into some same length of subvector but when it does not have a multiple of the vector, it should make other subvectors equal length but the last be shorter. This question is different from Split a vector into chunks in R as I want the shorter subvector to come last and the subvector length should not be greater than specified. I have a set of values (say 11

Split a string into array in Perl

落爺英雄遲暮 提交于 2020-04-07 19:10:55
问题 my $line = "file1.gz file2.gz file3.gz"; my @abc = split('', $line); print "@abc\n"; Expected output: file1.gz file2.gz file3.gz I want the output to be file1.gz in $abc[0] , file2.gz in $abc[1] , and file3.gz in $abc[2] . How do I split $line ? 回答1: Splitting a string by whitespace is very simple: print $_, "\n" for split ' ', 'file1.gz file1.gz file3.gz'; This is a special form of split actually (as this function usually takes patterns instead of strings): As another special case, split

Split a string into array in Perl

*爱你&永不变心* 提交于 2020-04-07 19:05:47
问题 my $line = "file1.gz file2.gz file3.gz"; my @abc = split('', $line); print "@abc\n"; Expected output: file1.gz file2.gz file3.gz I want the output to be file1.gz in $abc[0] , file2.gz in $abc[1] , and file3.gz in $abc[2] . How do I split $line ? 回答1: Splitting a string by whitespace is very simple: print $_, "\n" for split ' ', 'file1.gz file1.gz file3.gz'; This is a special form of split actually (as this function usually takes patterns instead of strings): As another special case, split

Split a string into array in Perl

佐手、 提交于 2020-04-07 19:05:46
问题 my $line = "file1.gz file2.gz file3.gz"; my @abc = split('', $line); print "@abc\n"; Expected output: file1.gz file2.gz file3.gz I want the output to be file1.gz in $abc[0] , file2.gz in $abc[1] , and file3.gz in $abc[2] . How do I split $line ? 回答1: Splitting a string by whitespace is very simple: print $_, "\n" for split ' ', 'file1.gz file1.gz file3.gz'; This is a special form of split actually (as this function usually takes patterns instead of strings): As another special case, split

Split string with commas to new line

别来无恙 提交于 2020-04-07 16:50:31
问题 I have a string like This is great day, tomorrow is a better day, the day after is a better day, the day after the day after that is the greatest day I wanted to basically split this one long string at the commas and insert a new line so it becomes This is great day tomorrow is a better day the day after is a better day the day after the day after that is the greatest day How can I do that ? 回答1: With the built in split and join methods var formattedString = yourString.split(",").join("\n")

Split string with commas to new line

假装没事ソ 提交于 2020-04-07 16:50:30
问题 I have a string like This is great day, tomorrow is a better day, the day after is a better day, the day after the day after that is the greatest day I wanted to basically split this one long string at the commas and insert a new line so it becomes This is great day tomorrow is a better day the day after is a better day the day after the day after that is the greatest day How can I do that ? 回答1: With the built in split and join methods var formattedString = yourString.split(",").join("\n")

842. Split Array into Fibonacci Sequence能否把数列返回成斐波那契数列

白昼怎懂夜的黑 提交于 2020-04-07 11:57:23
[抄题]: Given a string S of digits, such as S = "123456579" , we can split it into a Fibonacci-like sequence [123, 456, 579]. Formally, a Fibonacci-like sequence is a list F of non-negative integers such that: 0 <= F[i] <= 2^31 - 1 , (that is, each integer fits a 32-bit signed integer type); F.length >= 3 ; and F[i] + F[i+1] = F[i+2] for all 0 <= i < F.length - 2 . Also, note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself. Return any Fibonacci-like sequence split from S , or return [] if it cannot be done.

java split进行字符串分割

馋奶兔 提交于 2020-04-06 08:12:38
在java.lang包中有String.split()方法,返回是一个数组 我在应用中用到一些,给大家总结一下,仅供大家参考: 1、如果用“.”作为分隔的话,必须是如下写法,String.split("\\."),这样才能正确的分隔开,不能用String.split("."); 2、如果用“|”作为分隔的话,必须是如下写法,String.split("\\|"),这样才能正确的分隔开,不能用String.split("|"); “.”和“|”都是转义字符,必须得加"\\"; 3、如果在一个字符串中有多个分隔符,可以用“|”作为连字符,比如,“acount=? and uu =? or n=?”,把三个都分隔出来,可以用String.split("and|or"); 使用String.split方法分隔字符串时,分隔符如果用到一些特殊字符,可能会得不到我们预期的结果。 我们看jdk doc中说明 public String[] split(String regex) Splits this string around matches of the given regular expression. 参数regex是一个 regular-expression的匹配模式而不是一个简单的String,他对一些特殊的字符可能会出现你预想不到的结果,比如测试下面的代码用竖线 | 分隔字符串

SQL错误代码弹出提示信息类

我与影子孤独终老i 提交于 2020-04-03 07:30:51
截获SQL错误代码弹出提示信息类 Code : public class DBErrorCode { /// <summary> /// 根据错误代码弹出错误提示 /// </summary> /// <param name="code">错误代码</param> /// <param name="describe">描述</param> /// <returns>错误提示</returns> public static string DBError(int code, string describe) { #region 1、语法错误 string desTemp ="未知错误"; string eCode1 = "101、102、104、105、112、113、122、125、133、135、136、148、149、154、155、156、157、158、167、173、177、178、181、189、194、199、215、228、233、247、249、252、254、255、278、288、317、318、319、320、323、325、329、336、339、412、421、442、455、460、461、462、463、464、465、466、467、482、483、491、497、512、1003、1004、1005、1006、1008、1009、1010、1011