博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift_1_基本数据类型
阅读量:6375 次
发布时间:2019-06-23

本文共 1305 字,大约阅读时间需要 4 分钟。

import Foundationprintln("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
= ["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)")

转载地址:http://cotqa.baihongyu.com/

你可能感兴趣的文章
iOS笔记:内存管理
查看>>
python开发_python中str.format()
查看>>
HTML5, CSS3, ES5新的web标准和浏览器支持一览 转
查看>>
ThinkPHP3.0启动过程
查看>>
【leetcode】Longest Common Prefix (easy)
查看>>
JAX-WS(JWS)发布WebService
查看>>
Centos7安装docker-compse踩过的坑
查看>>
细说Nullable<T>类型
查看>>
oracle 插入表数据的4种方式
查看>>
7.Ajax
查看>>
Linux vi/vim编辑器常用命令与用法总结
查看>>
对于 url encode decode js 和 c# 有差异
查看>>
centos rz sz安装
查看>>
mysql 修改列为not null报错Invalid use of NULL value
查看>>
epoll源码分析
查看>>
朱晔和你聊Spring系列S1E4:灵活但不算好用的Spring MVC
查看>>
Java使用Try with resources自动关闭资源
查看>>
china-pub十一周年庆,多重优惠隆重登场,千万别错过哟!
查看>>
HDU 3068 最长回文(manacher算法)
查看>>
二叉树
查看>>