当前位置:网站首页>String string special interception processing according to symbols
String string special interception processing according to symbols
2022-07-19 04:55:00 【Xiaoxinai programming】
Project scenario :
Tips : Get the server address and then process the data
Now I know the server address , We upload the file to the server , Then if you want to save the file name or file suffix , It's going to cause problems , Then we need to process and analyze the string , You must analyze and summarize strings in the code , Then it can meet our existing project scenarios .
Problem description :
Tips : File name and suffix processing
The data we get is like this
String fileSite = "http://192.168.1.22:8081/imgPortl /ReadImg/181217775991024.jpg";
According to the data we got , I found all kinds of strange symbols in it , If you use simple splict It must be impossible to achieve the effect , Because various symbols and file upload paths will affect our interception , At this time, we need to think of other methods to analyze and process data .
Cause analysis :
Tips :string String processing can solve this problem
We use the position and screenshot of the string, and then quickly find the data for processing , We can achieve the effect we need .
substring() The function of is to intercept a part of the parent string
The first parameter int Index for start , Corresponding String The starting position in the number ,
The second parameter is the index position of the cutoff , Corresponding String End position in
1、 The length of the obtained string is :endIndex - beginIndex;
2、 from beginIndex Began to take , To endIndex end , from 0 Starting number , It does not include endIndex The character of position
Only with such data can we carry out the next analysis ,substring At this moment, the function of is more powerful than ever , At present, I only think that this treatment will be better solved , If there is a better way , Welcome to exchange .
Be careful :
1)、substring(a,b) Parameters in a Its value can be from the index value 0 Start ,
When a be equal to 0 when , It means that it starts from the first character of the string ,
That is, its substring contains the first character , Of course , You can also start with other characters that follow ;
2)、substring(a,b) Parameters in b, The maximum value can be Length of parent string ,
But it does not contain the index value b The character of
Solution :
// File address
String fileSite = "http://192.168.1.22:8081/imgPortl/ReadImg/181217775991024.jpg";
// File name
String oriName = fileSite.substring(fileSite.lastIndexOf("/")+1);
// file name
String substring = oriName.substring(0, oriName.lastIndexOf("."));
System.out.println(substring); // Output
summary :
1.xx.substring() The parameters in brackets are different , The effect will be very different , Detailed as follows :
2.xx.substring(0,2) It means taking the first and second characters (0,1,2 It means the first 、 Two 、 Three characters , The principle of including the head but not the tail only includes the first 、 Two characters ), Returns a new string ( Only the first and second characters specified );
3.xx.substring(2) It means to remove the first two characters , Returns a new string ( It only contains the remaining string after removing the first two characters )
4. In this method beginIndex Indicates the starting index of the interception , The intercepted string contains the characters corresponding to the starting index ;endIndex Indicates end index , The intercepted string does not include the characters corresponding to the ending index , If you don't specify endIndex, It indicates that it is intercepted to the end of the target string . This method is used to extract position beginIndex And location endIndex The string part between positions .
边栏推荐
猜你喜欢

简洁UI好玩的文字转换emoji表情微信小程序支持句子词语转换_源码

Conception finale: système distribué de gestion de la santé pour la prévention des épidémies hautement simultanées basé sur vue + socket + redis

TopicExchange交换机简单使用。

Hightec new aurix tc37x demo project

Basic operations of index library operation

负载均衡器ribbon实战

免签名模板审核的短信验证测试

MYSQL模糊匹配1,11,111这种相似字符串问题

快速掌握MIPI开发攻略

HighTec 新建 AURIX TC37X demo 工程
随机推荐
脱敏字段举例
有望取代Deepfake?揭秘今年超火的NeRF技
Tasking 新建 AURIX TC37X demo 工程
Quickly master Mipi development strategy
Service end interface test - test point of interface test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code
The n-beats model was released in 2020 and is 3% better than the winner of the M4 competition!
[vuforia] simple logic of image recognition
【Lipschitz】基于matlab的Lipschitz李氏指数仿真
FanoutExchange交换机简单使用
解决[email protected]: `node install.js` 的问题
OLTP 负载性能优化实践
[FPGA tutorial case 27] realize dual port RAM ping-pong structure through Verilog
mysql主从架构和读写分离、以及高可用架构
EMQX 压力测试踩得坑供大家参考
Tidb learning
TiDB 性能分析和优化
根据日期重新排列数据js
CKA 核心知识点概述
中台的订单系统