• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Swift_1_基本数据类型

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
import Foundation

println("Hello, World!");

var v1 = 1;
var v2 = 2;

println(" v1 is \(v1)  v2 is \(v2)");

var v3 = v1 + v2;

println("v3 is \(v3)");

//字符转换
var v4 : Double = Double(v3) + 3.14;

println("v4 is \(v4)");

var v5 = "hello"

let v6 = "world"

println(v5 + " " + v6);

//声明仅仅读类型变量
let v7 = 3.1415;

println("v7 is " + String(v7));

var arr = [1,2,4,6];

println("arr index 1 is \(arr[1])");

//声明字典
var airports: Dictionary<String, String> = ["TYO": "Tokyo", "DUB": "Dublin"];

var v8 = "10";

//字符串是否为空
if v8.isEmpty{
    println("v8 is true");
}

//遍历字符串
for character in "ddd1ew?"{
    println("char is " + character)
}

//字符串长度计算
let unusualMenagerie = "Koala ??

??, Snail ????, Penguin ?

???

, Dromedary ??

?

?

" println("unusualMenagerie has \(countElements(unusualMenagerie)) characters") var var9 = countElements(unusualMenagerie) println("var9 lenght is \(var9)") //比較字符串 let quotation = "We\'re a lot alike, you and I." let sameQuotation = "We\'re a lot alike, you and I." if quotation == sameQuotation { println("These two strings are considered equal") } //大写和小写转换 let normal = "Could you help me, please?" let shouty = normal.uppercaseString // shouty 值为 "COULD YOU HELP ME, PLEASE?

" let whispered = normal.lowercaseString // whispered 值为 "could you help me, please?" //String 转换 int var i :Int = "1".toInt()! println("\(i)")



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift基础语法 、 元组(Tuple)发布时间:2022-07-13
下一篇:
【Swift学习】Swift编程之旅---字符与字符串(五)发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap