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]);
}
}
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 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);
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 1 year ago.
Improve this question
How to check the beginning of a string contains a number in Java and convert the same into a number?
String s="-495asadad";
String s="-495asadad";
ParsePosition pp = new ParsePosition(0);
Number num = NumberFormat.getInstance().parse(s, pp);
if (pp.getIndex() == 0) {
System.out.println("No number there");
} else {
System.out.println("Number found: " + num);
}
Output:
Number found: -495
You will probably want to consider more precisely what constitutes a number and from that, how your NumberFormat should work.
The two-arg parse method tries to parse a number from the specified position. In this case position 0, the start of the string. If successful, it will update the position to after the number. If not, it will remain 0, so this is what I test in the if statement.
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
*/
}
}
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 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.