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

网站成品下载排版设计的网站

网站成品下载,排版设计的网站,目标网站上做关键字布局,怎么制作ppt课件字符串表达式运算符主要用于实现字符串操作,主要包括了大小写转换、字符串截取、拼接、替换等 一、准备工作 初始化字符串数据 db.strings.insertMany([{ "_id": "1", "comment": " Abc" },{ "_id": "2&…

字符串表达式运算符主要用于实现字符串操作,主要包括了大小写转换、字符串截取、拼接、替换等

一、准备工作

初始化字符串数据

db.strings.insertMany([{ "_id": "1", "comment": " Abc" },{ "_id": "2", "comment": "Hello World" },{ "_id": "3", "comment": " Hello World " }
])

二、去字符串($ltrim,$rtrim,$trim)

语法:

        去除开始位置的字符串:{ $ltrim: { input: <string>,  chars: <string> } }

        去除结束位置的字符串:{ $rtrim: { input: <string>,  chars: <string> } }

        去除开始和结束位置的字符串:{ $trim: { input: <string>,  chars: <string> } }

其中,

        input:代表的是需要去除字符的字符串

        chars:可选,代表的是需要去除的字符串;如果未定义,则去除空格

例子:去除开始位置的Hello

db.strings.aggregate([{$project: {"comment": {$ltrim: {input: "$comment",chars: "Hello"}}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " Abc" }
{ "_id" : "2", "comment" : " World" }
{ "_id" : "3", "comment" : " Hello World " }

可以看到,编号为2的数据中的Hello去掉了,编号为3的未去掉,原因是$ltrim是去除开始位置的字符串,而编号为3的数据的开始位置为空格

例子:去除结束位置的空格

db.strings.aggregate([{$project: {"comment": {$rtrim: {input: "$comment"}}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " Abc" }
{ "_id" : "2", "comment" : "Hello World" }
{ "_id" : "3", "comment" : " Hello World" }

例子:去除开始和结束位置的空格

db.strings.aggregate([{$project: {"comment": {$trim: {input: "$comment"}}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : "Abc" }
{ "_id" : "2", "comment" : "Hello World" }
{ "_id" : "3", "comment" : "Hello World" }

可以看出,$trim只是去除开始和结束位置的字符串

需要注意的是,$lrim,$rtrim,$trim只能在4.0及之后的版本才能使用

三、拼接($concat)

语法:{ $concat: [ <expression1>, <expression2>, ... ] }

将多个表达式的结果拼接到一起

例子:将编号和comment拼接到一起,后面再拼接上ok

db.strings.aggregate([{$project: {"comment": {$concat: [ "$_id", "$comment", "ok" ]}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : "1 Abcok" }
{ "_id" : "2", "comment" : "2Hello Worldok" }
{ "_id" : "3", "comment" : "3 Hello World ok" }

四、分割($split)

语法:{ $split: [ <string expression>, <delimiter> ] }

使用分隔符将字符串分割成字符串数组

其中,

        <string expression>:指的是待分割的字符串表达式

        <delimiter>:指的是字符串分隔符

例子:去除两边空格后使用空格分割comment

db.strings.aggregate([{$project: {"comment": {$split: [ { $trim: { input: "$comment" } }, " " ]}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : [ "Abc" ] }
{ "_id" : "2", "comment" : [ "Hello", "World" ] }
{ "_id" : "3", "comment" : [ "Hello", "World" ] }

五、转大写($toUpper)、转小写($toLower)

语法:

        转大写:{ $toUpper: <expression> }

        转小写:{ $toLower: <expression> }

例子:转换commet为大写

db.strings.aggregate([{$project: {"comment": {$toUpper: "$comment"}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " ABC" }
{ "_id" : "2", "comment" : "HELLO WORLD" }
{ "_id" : "3", "comment" : " HELLO WORLD " }

例子:转换commet为小写

db.strings.aggregate([{$project: {"comment": {$toLower: "$comment"}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " abc" }
{ "_id" : "2", "comment" : "hello world" }
{ "_id" : "3", "comment" : " hello world " }

六、替换($replaceOne,$replaceAll

语法:

        替换一个:{ $replaceOne: { input: <expression>, find: <expression>, replacement: <expression> } }

        替换所有:{ $replaceAll: { input: <expression>, find: <expression>, replacement: <expression> } }

例子:替换第一个l为o

db.strings.aggregate([{$project: {"comment": {$replaceOne: { input: "$comment", find: "l", replacement: "o" }}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " Abc" }
{ "_id" : "2", "comment" : "Heolo World" }
{ "_id" : "3", "comment" : " Heolo World " }

例子:替换所有的l为o

db.strings.aggregate([{$project: {"comment": {$replaceAll: { input: "$comment", find: "l", replacement: "o" }}}}
])

聚合查询的结果如下:

{ "_id" : "1", "comment" : " Abc" }
{ "_id" : "2", "comment" : "Heooo Worod" }
{ "_id" : "3", "comment" : " Heooo Worod " }
http://www.yayakq.cn/news/592139/

相关文章:

  • 深圳的设计企业网站seo优化技巧
  • 网站单页在线网站建设公司税率
  • 慕枫宁波网站建设怎么做网络推广挣钱
  • 成都定制网站设朔州海外网络推广
  • 大学 生免费商业网站设计可以建立网站的平台
  • 网站模板后台怎么做国外外包平台
  • 做网站用什么系统较好wordpress 添加分类
  • 哪儿能做网站建设网上书城网站开发的数据字典
  • 网站后台添加表格wordpress主题学习教程
  • wordpress 万能表单优化搜索引擎
  • 做网站 图片更好看在婚纱店做网站优化
  • 最好的网站建设公司有哪些上海外贸公司是国企吗
  • 学做网站需要学哪些软件mysql网站开发
  • 环球资源网的网站特色网页设计页面图片
  • 做网站广告词找王思奇admin.php wordpress
  • 网站模版调用标签教程郑州网站及优化
  • 设计公司网站运营企业网站可以备案几个
  • 做外贸网络推广网站软件开发工程师职业分析
  • 泉州市培训建设系统中心网站湛江大型网站模板建设
  • dede单本小说网站源码梅州市城乡建设局网站
  • 专业网站设计服务wordpress连接代码
  • 如何制作自己的网站链接教程代理公司在线观看
  • 网站怎么打开西安seo引擎搜索优化
  • 个人主页网站欣赏seo推广网站
  • 网站建设不包括以下哪个阶段wordpress游客看小图登陆查看大图
  • 公司网站成本杭州前十强装修公司有哪几家
  • 网站建设与管理自考重点wordpress代码缓存
  • 上海景泰建设有限公司网站珠海网站推广排名
  • seo是什么意思新手怎么做seo廊坊做网站优化
  • 静态做网站赣州网吧