Searching single char in String and seperate punctutation mark "
in
Programming Questions
•
1 year ago
Hello,
I have searching a lot here but couldn't find, what I need.
I have a string with many different characters and I want to count the different ones, like in the string is something like that: "asghkdsffk" and I want to have the number of "f"s - in this case f = 2. How can I managed that? I think I can not use equals() for that, because equals doesn't look for parts of a string, right?
And an other question: I seperate in this case every kind of punctuation marks by using splitTokens except for ". If I try to put " as part of splitTokens I get the Error Unterminated string constant and I think the program is thinking the parameter for tokens is ending at this point. But I don't know how to do it in an other way.
I'm very happy about every help!!
void setup() {
size(400, 400);
String text[] = loadStrings("deutsch.txt");
//Absätze sind im String alleZeilen durch ein : gekennzeichnet, bzw sind es die einzelnen Zeilen aus lines
//bound the paragraphs saved in many "lines" from text to one "line" in string alle Zeilen
String alleZeilen = join(text, ":");
//String wird auf Wörter reduziert
//cut out the punctuation marks and saved in woerter
String [] woerter = splitTokens(alleZeilen," ,:,.,?,!,-");
//hier werden die Wörter zu einer Reihe an Informationen gemacht, die nur aus Buchstaben besteht
//saved from many "lines" (woerter) to one "line"-string (alleBuchstaben)
String alleBuchstaben = join(woerter,"");
}
I have searching a lot here but couldn't find, what I need.
I have a string with many different characters and I want to count the different ones, like in the string is something like that: "asghkdsffk" and I want to have the number of "f"s - in this case f = 2. How can I managed that? I think I can not use equals() for that, because equals doesn't look for parts of a string, right?
And an other question: I seperate in this case every kind of punctuation marks by using splitTokens except for ". If I try to put " as part of splitTokens I get the Error Unterminated string constant and I think the program is thinking the parameter for tokens is ending at this point. But I don't know how to do it in an other way.
I'm very happy about every help!!
void setup() {
size(400, 400);
String text[] = loadStrings("deutsch.txt");
//Absätze sind im String alleZeilen durch ein : gekennzeichnet, bzw sind es die einzelnen Zeilen aus lines
//bound the paragraphs saved in many "lines" from text to one "line" in string alle Zeilen
String alleZeilen = join(text, ":");
//String wird auf Wörter reduziert
//cut out the punctuation marks and saved in woerter
String [] woerter = splitTokens(alleZeilen," ,:,.,?,!,-");
//hier werden die Wörter zu einer Reihe an Informationen gemacht, die nur aus Buchstaben besteht
//saved from many "lines" (woerter) to one "line"-string (alleBuchstaben)
String alleBuchstaben = join(woerter,"");
}
1