match empty rows in csv file through regex [closed] - java

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:
^[", ]*$
?

Related

How to convert String to array in Java [closed]

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);

should i use remmove and is this correct in java? [closed]

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

find Special word from text and put to array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
hi have some text like this :
What would you like to eat?
شما چي ميل  داريد؟
I’d like a bowl of tomato soup, please.
لطفا يک کاسه سوپ گوجه فرنگي برام بياريد
The waiter seems to be in a hurry to take our order.
گارسن بنظر مياد خيلي عجله داره که سفارش ما رو بياره
i want to Detect and put english Sentence in one array and Persian Sentence in another array
How can i do ؟
Assuming all your text is in a file and that English and persian translations are on different lines.
What you need to do is read each line from the file and check if it is ASCII or not.
How do you check that?
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
public class StringUtils {
static CharsetEncoder asciiEncoder =
Charset.forName("US-ASCII").newEncoder(); // or "ISO-8859-1" for ISO Latin 1
public static boolean isPureAscii(String v) {
return asciiEncoder.canEncode(v);
}
public static void main (String args[])
throws Exception {
String test = " برام ";
System.out.println(test + " isPureAscii() : " + StringUtils.isPureAscii(test));
test = "Real";
System.out.println(test + " isPureAscii() : " + StringUtils.isPureAscii(test));
/*
* output :
* برام isPureAscii() : false
* Real isPureAscii() : true
*/
}
}

Extract Verbs from Sentence [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to know if there is a way to extract verbs from a string.
As an example :
I'll eliminate you.
I want it to only extract "eliminate".
You probably want to be looking at using the Stanford PoS tagger (http://nlp.stanford.edu/software/tagger.shtml). It will tag the string with it's classification (e.g. verb, noun). You can then use a regular expression to pull out the verbs.
ArrayList<String> verbs = new ArrayList<>();
verbs.add("eliminate");
String yourtext = "I'll eliminate you";
for (String verb : verbs) {
int index = yourtext.indexOf(verb);
if (index >= 0) {
System.out.println("Found verb: " + verb + " at position: " + index);
}
}
I'll leave filling the verbs array up to you.

Java Scanner Delimiter - Extracting Multiple Sub-strings From a Single String [closed]

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]);
}
}

Categories

Resources