开发者

Get value with in two separator in java

开发者 https://www.devze.com 2023-01-27 04:28 出处:网络
I have a string with 开发者_开发知识库\"_\" separator like \"A_B_C_D_F\". I want to fetch the value after the 2nd \"_\" separator to 3rd separator. In this example the value will be \"C\".

I have a string with 开发者_开发知识库"_" separator like "A_B_C_D_F". I want to fetch the value after the 2nd "_" separator to 3rd separator. In this example the value will be "C".

Please help me to do this in efficient way.


String value = yourString.split("_")[2];


Split your string based on "_" and from the resultant array, get the array[2] element. That will be the output you need. Example to get it in one line of code is -

String str = myStr.split("_")[2];


You can use String.split function like so:

String value = "A_B_C_D";
String splits = value.split("_");
String secondValue = splits[2];
0

精彩评论

暂无评论...
验证码 换一张
取 消