zoukankan      html  css  js  c++  java
  • Swift

    1、变量:使用var声明

    var str:String = "HelloWorld"

    2、常量:使用let声明

     let count:Int = 1
    

     3、整形 

    有符号整形: Int,Int8,Int16,Int32,Int64
    无符号整形: UInt,UInt8,UInt16,UInt32,UInt64
    

    4、浮点型

     Float:32位浮点数类型
     Double:64位浮点数类型
    

    5、布尔型:BOOL

    6、字符串:  String

    (1)、判断是否为空isEmpty

     var str:String = ""
     if str.isEmpty {
         print("空字符串")
     }
    

     (2)、获取字符串数量

     let str = "baidu.com"
     print("(str.count)个字符")
    

     (3)、检查字符串是否有特定的前缀/后缀:hasPrefix/hasSuffix

     var str = "baidu.com"
    if str.hasSuffix(".com") {
         print("有指定的后缀.com")
     }
    

     (4)、还可以"()"在字符串里包裹变量,常量

     let name = "beijing"
     let msg = "欢迎来到(name)"
     print(msg)
    

     (5)、大小写转换

    可以通过字符串的uppercase()方法、lowercased()方法、capitalized属性来访问一个字符串的大写/小写/首字母大写

     let str = "welecome to beijing"
     var uppercase = str.uppercased()
     var lowercase = str.lowercased()
     var capitalized = str.capitalized
    

    7、字符:Character

    var doller:Character = "$"
    

    8、元组

    let myProject = (one:"game",two:1234)
    print("(myProject.one)")
    

    9、随机数

    //一个 1~100 的随机数(包括1和100)
    let temp = Int(arc4random()%100)+1 
    let temp = Int(arc4random_uniform(100))+1 
    
  • 相关阅读:
    VIJOS-P1340 拯救ice-cream(广搜+优先级队列)
    uva 11754 Code Feat
    uva11426 GCD Extreme(II)
    uvalive 4119 Always an Interger
    POJ 1442 Black Box 优先队列
    2014上海网络赛 HDU 5053 the Sum of Cube
    uvalive 4795 Paperweight
    uvalive 4589 Asteroids
    uvalive 4973 Ardenia
    DP——数字游戏
  • 原文地址:https://www.cnblogs.com/baidaye/p/8533971.html
Copyright © 2011-2022 走看看