当前位置:   article > 正文

split()和split(‘ ‘)的区别_c# .split(' ') 和 .split()

c# .split(' ') 和 .split()

split()分割的时候会把多个空格当做一个空格,split(’ ')分割的时候,多个空格会分割成多个空格。
split():

s1 = "we are family"#中间一个空格
s2 = "we  are  family"#中间两个空格
s3 = "we   are   family"#中间三个空格
s4 = "we    are    family"#中间四个空格

s1 = s1.split(" ")
s2 = s2.split(" ")
s3 = s3.split(" ")
s4 = s4.split(" ")

print(s1)#['we', 'are', 'family']
print(s2)#['we', '', 'are', '', 'family']
print(s3)#['we', '', '', 'are', '', '', 'family']
print(s4)#['we', '', '', '', 'are', '', '', '', 'family']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

split(’ '):

s1 = "we are family"#中间一个空格
s2 = "we  are  family"#中间两个空格
s3 = "we   are   family"#中间三个空格
s4 = "we    are    family"#中间四个空格

s1 = s1.split()
s2 = s2.split()
s3 = s3.split()
s4 = s4.split()

print(s1)#['we', 'are', 'family']
print(s2)#['we', 'are', 'family']
print(s3)#['we', 'are', 'family']
print(s4)#['we', 'are', 'family']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/786026
推荐阅读
相关标签
  

闽ICP备14008679号