zoukankan      html  css  js  c++  java
  • 判断字符串长度

    str="i am vincen, i am twenty years old!"
    
    for i in $str;do
        [ ${#i} -lt 4 ] && echo $i
    done

     上面例子使用的是  ${#i} 来计算

    var="i am vincen, and twenty years old!"
    for i in $var;do
        if [ `expr length $i` -gt 3 ];then
            echo $i
        fi
    done

     上面例子使用的是  expr length $i 来计算

    [root@rhel6 ~]# echo oldboy | awk '{print length}'  
    6

    使用 awk print length来计算

    [root@rhel6 script]# echo oldboy | wc -L
    6

    使用wc -L 更加简单

    请注意 wc -l -L

      -l, --lines            print the newline counts
      -L, --max-line-length  print the length of the longest line

  • 相关阅读:
    加载声音的过程
    onkeyup,onkeydown和onkeypress
    加载着色器的异常

    3
    1
    1
    java总结
    环路
    own address as source address
  • 原文地址:https://www.cnblogs.com/vincenshen/p/6547982.html
Copyright © 2011-2022 走看看