zoukankan      html  css  js  c++  java
  • lua string之find

    --计算字符串string中char的个数
    --better version
    local function count_char(string, char)
      local index = 0
      local count = 0
      while ture do
        index = string.find(string, char, i+1)
        if not index then break end
        count = count + 1
      end
      return count
    end

    local function count_char(string, char)
      local index = 0
      local count = 0
      while true do
        index = string.find(string, char)
        if not index then break end
        count = count + 1
        string = string.sub(string, index+1, #string)
      end
      return count
    end

    --test
    local s = ',hello,world,apple,'
    print(count_char(s, ','))
    print(count_char(s, 'p'))

    结论:工欲善其事,必先利其器



  • 相关阅读:
    JTA
    JPA
    深度优先搜索与广度优先搜索
    http和https区别
    数据库系统阶段特点
    Java中定义和声明
    java之集合ArrayList实例
    java实例之商品库
    java之封装
    java之类和对象
  • 原文地址:https://www.cnblogs.com/dotdog/p/4458027.html
Copyright © 2011-2022 走看看