当前位置:网站首页>Kotlin parsing String path knowledge
Kotlin parsing String path knowledge
2022-08-08 20:33:00 【Don't forget the original intention of z】
Parse String path, simple knowledge is stable
fun main(args: Array) {
val url = “/users/yole/kotlin-book/chapter.doc”
fun prasePath(path : String){
//The part before the last specified string is all saved
val a = path.substringBeforeLast("/")
println(a)
//The last oneAfter the specified string, it is the file name
val b = path.substringAfterLast("/")
println(b)
//String. Before is the file name
val fileName = b.substringBeforeLast(".")
//String. After that is the extension
println(fileName)
val extension = b.substringAfterLast(".")
println(extension)
}
//Create a method for parsing file paths using regular expressions
fun parsePath1(path:String){
//Create a regular expression
//(.+)/ The string before the last slash (.+)\The last .(.+) suffix name
val regex = """(.+) /(.+).(.+)""".toRegex()
println(regex)
//match
val matchResult = regex.matchEntire(path)
println(matchResult)
//Parse
if(matchResult !=null){
val (a,b,c) = matchResult.destructured
println(“a: a , n a m e a,name a,nameb,ext:$c”)
println(a)
}
}
prasePath(url)
parsePath1(url)
}
The output is as follows:
/users/yole/kotlin-book
chapter.doc
chapter
doc
The following is the printed result of the regular expression parsing
(.+)/(.+).(.+)
[email protected]
a:/users/yole/kotlin-book,namechapter,ext:doc
/users/yole/kotlin-book
边栏推荐
- Use fontforge to modify font, keep only numbers
- 2022-08-08 第六小组 瞒春 学习笔记
- 1088 N的阶乘
- 测试计划
- 数据解读!智能座舱“升级战”背后,本土供应链加速崛起
- 自然堂品牌焕新升级,携手代言人王一博彰显美妆年轻新态度
- Questions about Mac terminal custom commands and Mysql command
- 学习笔记:第三章 栈与队列
- Gartner:2022年全球半导体收入增长预计将放缓至7%,远低于2021年26.3%
- Superman is coming!Flutter realizes full-screen power animation!
猜你喜欢

rk3588使用npu进行模型转换和推理,加速AI应用落地

JMeter测试接口并发场景

学习笔记:第三章 栈与队列

IJCAI 2022 | Can Graph Neural Networks Detect Anomalies?
![Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception](/img/95/1041a1c23d020c272ca345d87019b2.png)
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

iMeta | 深圳先进院戴磊组开发可同时提取共存菌株的组成和基因成分谱的菌株分析工具...

西湖大学鞠峰组招聘【塑料降解 / 污水工程 / 微生物学】方向博士后和科研助理...

OpenEuler's Ways to Improve Resource Utilization 02: Effects under Typical Applications

com.alibaba.fastjson.JSONException: default constructor not found. class

Use fontforge to modify font, keep only numbers
随机推荐
莫让“学院派”限制我们的思维:在数组的中间位置删除数据一定比链表慢?
监控工具普罗米修斯(Prometheus)的介绍与安装
基于opencv的图片人像移除
【分享】如何在集简云平台自己进行应用开发?
CVPR 2022 ActivityNet竞赛冠军:中科院深圳先进院提出高低分双模态行为识别框架
基于opencv的实时睡意检测系统
JMeter测试接口并发场景
Some useful frameworks in Kotlin
实践篇1:深度学习之----LetNet之tensorflow2的实现
学习笔记:2.3 静态链表 循环链表 双向链表
学习笔记:XML
实践篇2:深度学习之----LetNet之tensorflow2的实现
Mysql management commands
Kotlin中IO流
高数_复习_第3章:一元函数积分学
测试计划
PHP使用glob()查找文件
自然堂品牌焕新升级,携手代言人王一博彰显美妆年轻新态度
莅临GOPS大会龙智展位,获取Forrester最新报告:《Forrester Wave:2021年第四季度企业服务管理报告》
学习笔记:栈的应用1_递归(重点)