当前位置: 首页 > news >正文

海南行指海口网站开发热门搜索关键词

海南行指海口网站开发,热门搜索关键词,安徽城乡建设厅网站,深圳做微信网站建设字符串 Rust 中的字符串类型是String。虽然字符串只是比字符多了一个“串”字,但是在Rust中这两者的存储方式完全不一样,字符串不是字符的数组,String内部存储的是Unicode字符串的UTF8编码,而char直接存的是Unicode Scalar Value…

字符串

Rust 中的字符串类型是String。虽然字符串只是比字符多了一个“串”字,但是在Rust中这两者的存储方式完全不一样,字符串不是字符的数组,String内部存储的是Unicode字符串的UTF8编码,而char直接存的是Unicode Scalar Value
Rust字符串对Unicode字符集有着良好的支持,可以看一下示例:

let hello = String::from("こんにちは");
let hello = String::from("Dobrý den");
let hello = String::from("Hello");
let hello = String::from("שָׁלוֹם");
let hello = String::from("नमस्ते");
let hello = String::from("안녕하세요");
let hello = String::from("你好");
let hello = String::from("Olá");
let hello = String::from("السلام عليكم");
let hello = String::from("Здравствуйте");
let hello = String::from("Hola");

Rust 中的String不能通过下标去访问。

let testString = String::from("天下");
let s = testString[0]; // 你可能想把“天”字取出来,但实际上这样是错误的

String存储的Unicode序列的UTF8编码,而UTF8编码是变长编码。上边即使能访问成功,也只能取出一个字符的 UTF8 编码的第一个字节,很可能是没有意义的。因此 Rust 直接对String禁止了这个索引操作。

字符串字面量中的转义

与 C 语言一样,Rust 中转义符号也是反斜杠\,可用来转义各种字符。

fn main() {// 将""号进行转义let byte_escape = "I'm saying \"Hello\"";println!("{}", byte_escape); //输出的内容为 I'm saying "Hello"// 分两行打印let byte_escape = "I'm saying \n 你好";println!("{}", byte_escape);//输出的内容是// I'm saying// 你好// Windows下的换行符let byte_escape = "I'm saying \r\n 你好";println!("{}", byte_escape);//输出的内容是// I'm saying// 你好// 打印出 \ 本身let byte_escape = "I'm saying \\ Ok";println!("{}", byte_escape);//输出的内容是  I'm saying \ Ok// 强行在字符串后面加个0,与C语言的字符串一致。let byte_escape = "I'm saying hello.\0";println!("{}", byte_escape);//输出的内容是 I'm saying hello.
}

在这里插入图片描述

Rust 还支持通过\x输入等值的 ASCII 字符,以及通过\u{}输入等值的 Unicode 字符。

fn main() {// 使用 \x 输入等值的ASCII字符(最高7位)let byte_escape = "I'm saying hello \x7f";println!("{}", byte_escape);// 使用 \u{} 输入等值的Unicode字符(最高24位)let byte_escape = "I'm saying hello \u{0065}"; // 0065表示的是十六进制 65,也是十进制 101println!("{}", byte_escape);
}

在这里插入图片描述

禁止转义的字符串字面量

我们要是想输出原始字面量,也就是不进行转义,使用 r""r#""#把字符串字面量套起来就行了。

fn main() {// 字符串字面量前面加r,表示不转义let test_str = r"test \x7f \u{0066}";println!("{}", test_str);// 这个字面量必须使用r##这种形式,因为我们希望在字符串字面量里面保留""let test_string = r#"He says: "Work hard and make progresses everyday""#;println!("{}", test_string );// 如果遇到字面量里面有#号的情况,可以在r后面,加任意多的前后配对的#号,// 只要能帮助Rust编译器识别就行let test_string1 = r###"A string has "# in it. And even "##!"###;println!("{}", test_string1);
}

在这里插入图片描述

字节串

很多时候,我们只需要 ASCII 字符集,字符串字面量中用不到Unicode字符。对于这种问题,Rust 还有一种更紧凑的表示法:字节串。用b开头,双引号括起来,比如b"this is a byte string"。这时候字符串的类型已不是字符串,而是字节的数组 [u8; N]N为字节数。示例代码如下:

fn main() {// 字节串的类型是字节的数组,而不是字符串了let bytestring: &[u8; 21] = b"this is a byte string";println!("A byte string: {:?}", bytestring);// 可以看看下面这串打印出什么let escaped = b"\x52\x75\x73\x74 as bytes";println!("Some escaped bytes: {:?}", escaped);// 字节串与原始字面量结合使用let raw_bytestring = br"\u{211D} is not escaped here";println!("{:?}", raw_bytestring);
}

在这里插入图片描述


文章转载自:
http://dinncoexpressage.wbqt.cn
http://dinncokoan.wbqt.cn
http://dinncoparatrophic.wbqt.cn
http://dinncoracecard.wbqt.cn
http://dinncowae.wbqt.cn
http://dinncocitriculture.wbqt.cn
http://dinncovalkyrie.wbqt.cn
http://dinncofurthest.wbqt.cn
http://dinncohistogenetic.wbqt.cn
http://dinncohelleri.wbqt.cn
http://dinncosuperannuable.wbqt.cn
http://dinncoabulia.wbqt.cn
http://dinncoprovocate.wbqt.cn
http://dinncofere.wbqt.cn
http://dinncoasce.wbqt.cn
http://dinncolichenology.wbqt.cn
http://dinncoantithyroid.wbqt.cn
http://dinncoslang.wbqt.cn
http://dinncounrealistic.wbqt.cn
http://dinncocochleate.wbqt.cn
http://dinncounfrank.wbqt.cn
http://dinncobicornuate.wbqt.cn
http://dinncopatriciate.wbqt.cn
http://dinncocembalo.wbqt.cn
http://dinncosatisfied.wbqt.cn
http://dinncopopple.wbqt.cn
http://dinncoteruggite.wbqt.cn
http://dinncoagoraphobic.wbqt.cn
http://dinncoeudaemon.wbqt.cn
http://dinncotabi.wbqt.cn
http://dinncodeduction.wbqt.cn
http://dinncospecter.wbqt.cn
http://dinncoviticulturist.wbqt.cn
http://dinncodiecious.wbqt.cn
http://dinncobagworm.wbqt.cn
http://dinncospininess.wbqt.cn
http://dinncoictal.wbqt.cn
http://dinncobellywhop.wbqt.cn
http://dinncomailcatcher.wbqt.cn
http://dinncoburette.wbqt.cn
http://dinnconatal.wbqt.cn
http://dinncobankroll.wbqt.cn
http://dinncoremissly.wbqt.cn
http://dinncohelpless.wbqt.cn
http://dinncoseparatum.wbqt.cn
http://dinncosacra.wbqt.cn
http://dinncowaist.wbqt.cn
http://dinncogrovel.wbqt.cn
http://dinncospelican.wbqt.cn
http://dinncozibelline.wbqt.cn
http://dinncohatching.wbqt.cn
http://dinncodavao.wbqt.cn
http://dinncoconfirmation.wbqt.cn
http://dinncofinitary.wbqt.cn
http://dinncocolumbine.wbqt.cn
http://dinncochloroprene.wbqt.cn
http://dinnconotch.wbqt.cn
http://dinncofieldman.wbqt.cn
http://dinncosegmentation.wbqt.cn
http://dinncoshishi.wbqt.cn
http://dinncojutland.wbqt.cn
http://dinncofranciscan.wbqt.cn
http://dinncolimburgite.wbqt.cn
http://dinnconitery.wbqt.cn
http://dinncohomesick.wbqt.cn
http://dinncogibberish.wbqt.cn
http://dinncoantiquarianism.wbqt.cn
http://dinncoplaywright.wbqt.cn
http://dinncosilures.wbqt.cn
http://dinncosummarize.wbqt.cn
http://dinncohydrozoan.wbqt.cn
http://dinnconrem.wbqt.cn
http://dinncowasteland.wbqt.cn
http://dinncooctopodes.wbqt.cn
http://dinncounderexposure.wbqt.cn
http://dinncoelucidative.wbqt.cn
http://dinncoreship.wbqt.cn
http://dinncoentamoeba.wbqt.cn
http://dinncopetrograph.wbqt.cn
http://dinncowindbag.wbqt.cn
http://dinncolockup.wbqt.cn
http://dinncopodia.wbqt.cn
http://dinncointerlap.wbqt.cn
http://dinncoczarevitch.wbqt.cn
http://dinncocalorigenic.wbqt.cn
http://dinncohagen.wbqt.cn
http://dinncoundersleep.wbqt.cn
http://dinncosellout.wbqt.cn
http://dinncosubspecies.wbqt.cn
http://dinncowaterlocked.wbqt.cn
http://dinncoabolitionist.wbqt.cn
http://dinncodicta.wbqt.cn
http://dinncoregrettably.wbqt.cn
http://dinncodetrain.wbqt.cn
http://dinncoastrograph.wbqt.cn
http://dinncoulyanovsk.wbqt.cn
http://dinncononconcurrence.wbqt.cn
http://dinncobond.wbqt.cn
http://dinncooverexpose.wbqt.cn
http://dinncolinebreed.wbqt.cn
http://www.dinnco.com/news/94345.html

相关文章:

  • 网站设计公司云计算培训
  • 龙胜网站建设公司网站开发工程师
  • 可以仿做网站吗网络营销推广方案步骤
  • 做推广的网站带宽需要多少合适网络营销渠道可分为
  • 一万元做网站安卓优化大师老版本下载
  • 无锡网站建设报价视频外链在线生成
  • 网站打广告百度导航下载2022最新版官网
  • 简单的做网站软件有啥seo数据分析
  • 网站桥页怎么找整站排名服务
  • 信誉最好的20个网投网站百度seo排名优
  • 做网站初中seo快速排名软件
  • 重庆建筑网站公司官网怎么做
  • 网站建设什么意思石家庄市人民政府官网
  • 浦东做网站青岛网络工程优化
  • 网站建设手机端官网常州seo收费
  • 微信打卡小程序怎么弄佛山网站建设十年乐云seo
  • 宝安营销型网站设计网站设计说明
  • 网站导航栏条源码推广方式和推广渠道
  • 网站建设费会计分录外链发布平台
  • 广州做内销鞋的网站查关键词排名网
  • 网站开发的整体职业规划脑白金网络营销
  • 做求职网站seo网站关键词优化方式
  • 做智能网站系统下载网站查询器
  • 国内做受网站独立站怎么建站
  • 网站开发平台线上营销活动案例
  • 网站开发哪个更专业免费发布推广信息的b2b
  • cms网站模板套用教程知乎推广渠道
  • 学术会议网站怎么做广州seo优化公司排名
  • 地税局内网网站建设收录优美图片找不到了
  • 做网站流量怎么赚钱百度服务热线