当前位置:网站首页>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 .
边栏推荐
- 网址在线封装APK系统源码
- And predicts that nerf will eventually replace deepfake
- Emqx pressure test tread pit for your reference
- Warriors of the Visual Studio, Assemble! (Visual Studio的勇士们,汇编吧!) 原创 2009年07月12日 19:40:00 标签:汇编 /mic
- 解决[email protected]: `node install.js` 的问题
- 免签名模板审核的短信验证测试
- NoSQL概述
- 赚钱大师小程序【最新版5.9.9】商城/佣金即时提现/分销推广/话费充值/美团饿了么外卖
- RestAPI
- Minio installation, deployment and use
猜你喜欢
随机推荐
Constraints on MySQL tables (Basics)
ThreadLocal线程安全示例及其原理
Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code
3.RestClient查询文档
UE plug-in electronicnodes 5.0.0/4.23-4.27
OLTP Load Performance Optimization Practice
负载均衡器ribbon实战
DSL查询文档
天道酬勤,保持热爱
MYSQL两个查询条件取并集然后进行查询
TopicExchange交换机简单使用。
微众对接机制备忘
masm32写程序
Introduction to redis
Project team summer vacation summary 02
一文了解Zipkin
解决[email protected]: `node install.js` 的问题
一文带你了解HAProxy
Redis简介
Reproduction of XOR and encryption decryption







![[vuforia] simple logic of image recognition](/img/c4/c3640fd37ec75d89da367d310b10a6.png)

