fateame 发表于 2017-5-6 10:31:13

字符串字符Python 字符串操作 字符串字符

  这段时间一直在学习字符串字符之类的问题,现在正好有机会和大家讨论一下.
  #strcpy(sStr1,sStr2)
  sStr1 =
  'strcpy'
  sStr2 = sStr1 sStr1 =
  'strcpy2'
  print
  sStr2
  #strcat(sStr1,sStr2)
  sStr1 =
  'strcat'
  sStr2 =
  'append'
  sStr1 += sStr2
  print
  sStr1
  #strchr(sStr1,sStr2)
  sStr1 =
  'strchr'
  sStr2 =
  'r'
  nPos = sStr1.
  index
  (
  sStr2
  )
  print
  nPos
  #strcmp(sStr1,sStr2)
  sStr1 =
  'strchr'
  sStr2 =
  'strch'
  print
  cmp
  (
  sStr1,sStr2
  )
  #strspn(sStr1,sStr2)
  sStr1 =
  '12345678'
  sStr2 =
  '456'
  #sStr1 and chars both in sStr1 and sStr2
  print
  len
  (
  sStr1
  and
  sStr2
  )
  #strlen(sStr1)
  sStr1 =
  'strlen'
  print
  len
  (
  sStr1
  )
  #strlwr(sStr1)
  sStr1 =
  'JCstrlwr'
  sStr1 = sStr1.
  upper
  (
  )
  print
  sStr1
  #strncat(sStr1,sStr2,n)
  sStr1 =
  '12345'
  sStr2 =
  'abcdef'
  n =
  3
  sStr1 += sStr2
  [
  0
  :n
  ]
  print
  sStr1
  #strncmp(sStr1,sStr2,n)
  sStr1 =
  '12345'
  sStr2 =
  '123bc'
  n =
  3
  print
  cmp
  (
  sStr1
  [
  0
  :n
  ]
  ,sStr2
  [
  0
  :n
  ]
  )
  #strncpy(sStr1,sStr2,n)
  sStr1 =
  ''
  sStr2 =
  '12345'
  n =
  3
  sStr1 = sStr2
  [
  0
  :n
  ]
  print
  sStr1
  #stricmp(sStr1,sStr2)
  sStr1 =
  'abcefg'
  sStr2 =
  'ABCEFG'
  print
  cmp
  (
  sStr1.
  upper
  (
  )
  ,sStr2.
  upper
  (
  )
  )
  #strnset(sStr1,ch,n)
  sStr1 =
  '12345'
  ch =
  'r'
  n =
  3
  sStr1 = n
  *
  ch + sStr1
  [
  3
  :
  ]
  print
  sStr1
  #strpbrk(sStr1,sStr2)
  sStr1 =
  'cekjgdklab'
  sStr2 =
  'gka'
  nPos =
  -1
  for
  c
  in
  sStr1:
  if
  c
  in
  sStr2: nPos = sStr1.
  index
  (
  c
  )
  break
  print
  nPos
  #strrev(sStr1)
  sStr1 =
  'abcdefg'
  sStr1 = sStr1
  [
  ::
  -1
  ]
  print
  sStr1
  python strstr
  #strstr(sStr1,sStr2)
  sStr1 =
  'abcdefg'
  sStr2 =
  'cde'
  print
  sStr1.
  find
  (
  sStr2
  )
  #strtok(sStr1,sStr2)
  sStr1 =
  'ab,cde,fgh,ijk'
  sStr2 =
  ','
  sStr1 = sStr1
  [
  sStr1.
  find
  (
  sStr2
  )
  +
  1
  :
  ]
  print
  sStr1
  文章结束给大家分享下程序员的一些笑话语录: 那是习惯决定的,一直保持一个习惯是不好的!IE6的用户不习惯多标签,但是最终肯定还是得转到多标签的浏览器。历史(软件UI)的进步(改善)不是以个人意志(习惯)为转移的!
页: [1]
查看完整版本: 字符串字符Python 字符串操作 字符串字符