Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have a string String myStringArray = "[491174, 414529, 414557]";. I want output 491174, 414529, 414557 just this part. I tried many methods to convert string to array and many other things. I tried something I'm adding the code below.
My Code
String myStringArray = "[491174, 414529, 414557]";
String newArray = myStringArray.replaceAll(" ", "");
System.out.println("Before Remove : " + newArray);
String remove = newArray.replaceAll("[^a-zA-Z0-9]", ",");
String rm = remove.replaceFirst(",", "");
System.out.println("After Remove : " + rm);
Output
Before Remove : [491174,414529,414557]
After Remove : 491174,414529,414557,
As you can see I have , in the end and I don't know how to remove this ,. Please help me if you can.
rm = rm.substring(0, rm.length() - 1);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
in the exercise they told if string contain 00 or 0 remove it
String rse="12+00+9+88";
String re="[0]{1,2}\\+";
String oper[]=chaine.split("[0-9]{1,2}\\+");
for(int i=1;i<oper.length;i++) {
if (oper.equals(re)) {
}
}
You may juse use String.replaceAll and use 2 regexes
(0+)\+ to remove zeros followed by a +
\+(0+), specific case when zeros are the last one, the + is before it
List<String> values = Arrays.asList(
"12+00+9+88",
"12+0+9+88",
"00+9+88",
"0+9+88",
"12+00",
"12+0"
);
for (String s : values) {
String r = s.replaceAll("(0+)\\+", "").replaceAll("\\+(0+)", "");
System.out.println(r);
}
12+9+88
12+9+88
9+88
9+88
12
12
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have csv file with below data How I can remove empty rows in java through regex I tried using ^,+$ but Its not working
"Temp-A007","Default","Importing","","",""
"","",""
You can do it through RegEx. Simply use input.replaceAll("(\"\\s*\"\\s*,?)", "");
Output
input : "Temp-A007", "","Default","Importing","","",""
output : "Temp-A007", "Default","Importing",
Code
public class Test {
public static void main(String args[]) {
String input = new String("\"Temp-A007\", \"\",\"Default\",\"Importing\",\"\",\"\",\"\" ");
String output = input.replaceAll("(\"\\s*\"\\s*,?)", "");
System.out.println("input : " + input);
System.out.println("output : " + output);
}
}
An "empty" row will have at most commas, quotes, and spaces, no? How about:
^[", ]*$
?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string Saxon Securitie/Logo/horse-logo.jpg_1413458235818 in format "A/B/C"
I want the result as C by removing "A/B/" from the above string and get a result
String C = "horse-logo.jpg_1413458235818"
Try:
String s = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
String c = s.substring(s.lastIndexOf("/") + 1);
System.out.println(c);
String filePath = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
String fileName = new File(filePath).getName();
See https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
You can use String.lastIndexOf to do that :
String path = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
int index = path.lastIndexOf("/");
String fileName = index == -1 ? null : path.substring(index + 1);
I'm not going to give you answer but you could easily use split function in java that you can learn about here. and at first split with space then split with /
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have searched nearly all pages on Stackoverflow but still have not found out how to do this. I have the following string (which is being parsed from file):
f: (matchQuan
(Recipe
(Unique FoodType "slurpee" "xxx-xxx-eee-ddd"))
(Unique IngredType "slurpee" "qqq-rrr-sss") "slurpee"
(Cup-Vol 12)).
Now, I want to parse this string again and extract the string matchQuan, the slurpee, the string Unique and FoodType and Recipe and the ID numbers i.e. xxx-xxx-eee-ddd.
How would I do something like this with multiple extractions from a single string? I can't use Scanner.next() I don't believe because it advances to the next token in string.
Thanks!
Will this help for you?
public static void getString() {
String str = "f: (matchQuan " +
"(Recipe "+
"(Unique FoodType" + " slurpee"+ " xxx-xxx-eee-ddd"+
"(Unique IngredType"+ " slurpee"+ " qqq-rrr-sss"+" slurpee" +
" (Cup - Vol 12)).";
String newStr=str.replaceAll("\\(","").replaceAll("\\)","");
String[] arrStr=newStr.split(" ");
for (int i=0;i<arrStr.length;i++){
System.out.println(arrStr[i]);
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
hello I have this string that is a data table I want to test if the string contains more than _ then we are cutting the chains and in each sub string in a table row
I use talend and my input is an excel
I'm really stuck who can help me please
exemple:
JEN3030_1_2_3
JEN3030_1
JEN3030_2
JEN3030_3
Try String.split()...
String input = "JEN3030_1_2_3"; //or whatever
List<String> output = new ArrayList<String>();
String[] parts = input.split("_");
for(int i = 1; i < parts.length; i++) {
output.add(parts[0] + "_" + parts[i]);
}