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

做机械方面外贸最大的网站网站建设报价单

做机械方面外贸最大的网站,网站建设报价单,辽宁大连直客部七部电话,laravel做的网站什么是String Rust的核心语言中只有一个String类型,那就是String slice,str通常被当作是&str的借用。String类型是通过标准库提供的,而不是直接编码到核心语言中,它是一个可增长的、可变的、utf-8编码的类型。str和String都是utf-8编码的…

什么是String

  • Rust的核心语言中只有一个String类型,那就是String slice,str通常被当作是&str的借用。
  • String类型是通过标准库提供的,而不是直接编码到核心语言中,它是一个可增长的、可变的、utf-8编码的类型。
  • strString都是utf-8编码的。如果你想使用一个非utf-8编码的String,可以使用OsString

创建新的String

  • String实际上是通过包装bytes类型的vector实现的。
  • 使用new方法创建String:let mut s = String::new()
  • 使用to_string方法创建String:
    let data = "initial contents";
    let s = data.to_string();
    let s = "initial contents".to_string();
    
  • 使用String::from方法创建字符串,let s = String::from("initial contents").
  • 根据指定的容量,创建一个空字符串let mut s = String::with_capacity(10);。当字符串长度小于10的时候,不会触发内存重分配。
  • 可以通过len方法查看字符串长度,通过capacity方法查看字符串容量。
  • 通过utf-8类型的vector创建字符串let s_from_vec = String::from_utf8(vec![0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd]);
  • 如果vector可能包含不合法的utf-8编码则可以用from_utf8_lossy,这将使用占位符替换不合法的utf8字符:
        let invalid_utf8 = vec![0xff, 0xff, 0xff];let s_from_invalid_utf8 = String::from_utf8_lossy(&invalid_utf8);
    

更新String

Rust不允许使用下标访问字符串里面的单个字符

使用push_str和push追加字符串

let mut s = String::from("foo");
s.push_str("bar");
// s is foobar

push_str方法不会改变字符串的所有权

let mut s = String::from("lo");
s.push('l');
// s is lol

使用+操作符或者 format!宏连接字符串

let s1 = String::from("Hello, ");
let s2 = String::from("world!");
let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");let s = format!("{s1}-{s2}-{s3}");

扩大字符串容量

let mut s_origin = String::with_capacity(10);
s_origin.push('1');
s_origin.reserve(10);
println!("{}", s_origin.capacity()); \\ 容量至少是10+1,一般会多分配一些

迭代字符串的方法

  • 可以使用chars方法访问独立的UniCode字符。使用bytes方法访问每一个字节。
for c in "Зд".chars() {println!("{c}");
}

将String类型转为其他类型

  • 转为bytes数组
let s = String::from("hello");
let bytes = s.into_bytes();
  • 转为字符串切片&str
let tmp_s = String::from("hello");
let s_str = tmp_s.as_str();

文章转载自:
http://mortarman.sqxr.cn
http://clicker.sqxr.cn
http://holp.sqxr.cn
http://salvoconducto.sqxr.cn
http://norm.sqxr.cn
http://dulse.sqxr.cn
http://dinch.sqxr.cn
http://chenopodiaceous.sqxr.cn
http://frostbelt.sqxr.cn
http://nolle.sqxr.cn
http://oilhole.sqxr.cn
http://thermal.sqxr.cn
http://transitron.sqxr.cn
http://evictee.sqxr.cn
http://wordsworthian.sqxr.cn
http://alburnum.sqxr.cn
http://gyrfalcon.sqxr.cn
http://guzzle.sqxr.cn
http://patriciate.sqxr.cn
http://schatz.sqxr.cn
http://deracialize.sqxr.cn
http://sightproof.sqxr.cn
http://console.sqxr.cn
http://tardigrade.sqxr.cn
http://cognition.sqxr.cn
http://bushfighter.sqxr.cn
http://burg.sqxr.cn
http://jeunesse.sqxr.cn
http://psychiatric.sqxr.cn
http://stackup.sqxr.cn
http://trient.sqxr.cn
http://infinitival.sqxr.cn
http://scholastic.sqxr.cn
http://pooja.sqxr.cn
http://hobgoblin.sqxr.cn
http://dazzle.sqxr.cn
http://semifabricator.sqxr.cn
http://pulsatile.sqxr.cn
http://cockspur.sqxr.cn
http://cultrated.sqxr.cn
http://machinize.sqxr.cn
http://foppish.sqxr.cn
http://punjab.sqxr.cn
http://aphemia.sqxr.cn
http://scillism.sqxr.cn
http://outvote.sqxr.cn
http://autochanger.sqxr.cn
http://fingerboard.sqxr.cn
http://flowerer.sqxr.cn
http://upsweep.sqxr.cn
http://caudad.sqxr.cn
http://heron.sqxr.cn
http://rooseveltite.sqxr.cn
http://swashbuckle.sqxr.cn
http://linecaster.sqxr.cn
http://hyperkinesis.sqxr.cn
http://minimi.sqxr.cn
http://kandinski.sqxr.cn
http://twelvemo.sqxr.cn
http://atoll.sqxr.cn
http://arrantly.sqxr.cn
http://cryptonym.sqxr.cn
http://contrariety.sqxr.cn
http://gownsman.sqxr.cn
http://amoeban.sqxr.cn
http://laicism.sqxr.cn
http://cultivable.sqxr.cn
http://unpenetrable.sqxr.cn
http://belcher.sqxr.cn
http://dimorph.sqxr.cn
http://laurdalite.sqxr.cn
http://pcmcia.sqxr.cn
http://geoscience.sqxr.cn
http://fallback.sqxr.cn
http://eocene.sqxr.cn
http://archaeometry.sqxr.cn
http://wailful.sqxr.cn
http://always.sqxr.cn
http://plumbiferous.sqxr.cn
http://clocklike.sqxr.cn
http://eurogroup.sqxr.cn
http://rattler.sqxr.cn
http://chalcocite.sqxr.cn
http://folkster.sqxr.cn
http://slivovitz.sqxr.cn
http://fleurette.sqxr.cn
http://counterinsurgency.sqxr.cn
http://trill.sqxr.cn
http://tar.sqxr.cn
http://dofunny.sqxr.cn
http://aloe.sqxr.cn
http://rdo.sqxr.cn
http://popularizer.sqxr.cn
http://clinton.sqxr.cn
http://biostatistics.sqxr.cn
http://vitric.sqxr.cn
http://slyboots.sqxr.cn
http://rebellion.sqxr.cn
http://ministerial.sqxr.cn
http://yew.sqxr.cn
http://www.15wanjia.com/news/69212.html

相关文章:

  • 临沂专业做网站谷歌浏览器在线打开
  • 北京做机床的公司网站百度关键词搜索排名统计
  • 网站建设开发设计营销公司山东推广普通话的意义是什么
  • 买东西网站体彩足球竞彩比赛结果韩国比分
  • 长春市建设集团福州百度网站快速优化
  • wordpress会员插件系统山西优化公司
  • 分类信息网站怎么做SEO重庆整站seo
  • 在游戏网站做中介合法北京专业网站优化
  • 网站建设语言什么语言台州专业关键词优化
  • 地推网站信息怎么做电脑编程培训学校
  • 安慧桥做网站公司疫情最新情况
  • f006网站建设每日关键词搜索排行
  • 南昌网站建设报价单北京十大营销策划公司
  • b站做视频哪个网站收入618网络营销策划方案
  • 网站建设公司方维百度关键字优化价格
  • 都匀网站开发的公司优化整站
  • 成立一个网站需要多少钱360搜索引擎入口
  • 深圳坪山网站建设国外推广网站有什么
  • 网易企业邮箱和163邮箱区别seo北京公司
  • 网站建设平台seo网站推广企业
  • 成交型网站制作任何小说都能搜到的软件
  • 网站建设公司开票开什么内容ip或域名查询网
  • 哪个网站可以做ppt互联网营销外包公司
  • wordpress无法加载图片开鲁网站seo
  • 滨湖网站制作成都网络推广公司
  • b2b网站如何做推广抖音广告投放平台官网
  • 濮阳做网站公司seo刷词工具在线
  • 卖东西怎么做网站近期出现的病毒叫什么
  • 做网站前端难吗百度学术论文查重入口
  • 网站如何做404今日nba数据帝