What is simplest way to append text to richTextBox1?
Also I found that to set it from std::string is not very simple
richTextBox1->Text= gcnew String ( str.c_str() ) ;
How to deal with these operations in everyday life?
I think you can try:
String str = "12345";
richTextBox1->Text += str;
Related
First I need to detect if message from player contains math problem
like I get 2 messages from him
char* message1 = "Please solve this math problem";
char* message2 = "How much is 1 + 2 ?";
These messages are not static, player can say different messages.
I need to process message1 and message2
I need to detect math problem and cut it like see message2 and I need it to be "1+2"
char* mathProblemFromMessage = "1+2"; // <- I need to get this from message also detect if message contains any math problem before
double answer = te_interp(mathProblemFromMessage, 0);
printf("Answer is %f\n", answer);
my current code
std::string msg = Message;
if (func.contains_math_operators(msg.c_str()) && func.contains_number(msg.c_str()))
{
double answer = te_interp(Message, 0);
}
I think it fails and always results 0 because msg is "Player: 1+1" I need to cut math problem from it, I dont know how to do it...a
Find a position of the first digit in that string and get a substring from that point:
std::size_t found = msg.find_first_of("0123456789");
if(found != std::string::npos)
{
std::string sub = msg.substr(found);
double answer = te_interp(sub, 0);
}
If that also fails, try to trim invalid tail.
You may want to extend that find_first_of above to include open paren (, unary minus - or some supported function names (I am not familiar with TinyExpr)
I am looking for a way to get a String between 2 Strings using Arduino. This is the source String:
Hello, my name is John Doe# and my favourite number is 32#.
The output has to be:
String name = "John Doe"; //Between "name is " and "#"
String favouriteNumber = "32"; //Between "number is " and "#"
How can this be achieved with Arduino?
I am not able to find any information online about this. Those examples for C are not working anyway. I understand that using String is not recommended in Arduino, but I have to do it this way to make things simpler.
By the way, this method of using a '#' to indicate the end of the data is not an ideal way to do it as I would like the input to be more human readable and more natural. Would anyone please suggest another way to do this as well?
Thanks in advance!
Function midString find the substring that is between two other strings "start" and "finish". If such a string does not exist, it returns "". A test code is included too.
void setup() {
test();
}
void loop() {
delay(100);
}
String midString(String str, String start, String finish){
int locStart = str.indexOf(start);
if (locStart==-1) return "";
locStart += start.length();
int locFinish = str.indexOf(finish, locStart);
if (locFinish==-1) return "";
return str.substring(locStart, locFinish);
}
void test(){
Serial.begin(115200);
String str = "Get a substring of a String. The starting index is inclusive (the corresponding character is included in the substring), but the optional ending index is exclusive";
Serial.print(">");
Serial.print( midString( str, "substring", "String" ) );
Serial.println("<");
Serial.print(">");
Serial.print( midString( str, "substring", "." ) );
Serial.println("<");
Serial.print(">");
Serial.print( midString( str, "corresponding", "inclusive" ) );
Serial.println("<");
Serial.print(">");
Serial.print( midString( str, "object", "inclusive" ) );
Serial.println("<");
}
just searched for this and saw no answer so i cooked one up.
i prefer working with String as well because of code readability and simplicity.
for me its more important than squeezing every last drop of juice out of my arduino.
String name = GetStringBetweenStrings("Hello, my name is John Doe# and my favourite number is 32#." ,"name is ","#");
String GetStringBetweenStrings(String input, String firstdel, String enddel){
int posfrom = input.indexOf(firstdel) + firstdel.length();
int posto = input.indexOf(enddel);
return input.substring(posfrom, posto);
}
watch out for the first case its fine, but for the second one you would have to change the second filter sting to "#." so it doesn't use the first occurrence of the #
I am trying to store the string value into vector. And then after storing I want to store in string one by one. In first step split the sting by "," and store into vector. And again try to retrive and get into string.
My code:
CString sAssocVal = "test1, test2, test3";
istringstream ss( sAssocVal.GetBuffer(sAssocVal.GetLength()) );
vector<string> words;
string token;
while( std::getline(ss, token, ',') )
{
words.push_back( token );
}
Try to again retrive from vector:
for(int i = 0; i<words.size(); i++)
std::string st= words[i];
But the value of st is getting NULL always.
where I am missing some thing.
AFAIK the problem is the istringstream initialization, a small modification makes your example work:
http://coliru.stacked-crooked.com/a/698818655cbba4e7
You could first convert CString to std::string, there are a lot of topics about that problem
I resolved this is by using this code.
CString st;
for(int i = 0; i<words.size(); i++)
st= words[i].c_str();
How to remove diacritic marks from a string in Qt. For example, this:
QString test = QString::fromUtf8("éçàÖœ");
qDebug() << StringUtil::removeAccents(test);
should output:
ecaOoe
There is not straighforward, built-in solution in Qt. A simple solution, which should work in most cases, is to loop through the string and replace each character by their equivalent:
QString StringUtil::diacriticLetters_;
QStringList StringUtil::noDiacriticLetters_;
QString StringUtil::removeAccents(QString s) {
if (diacriticLetters_.isEmpty()) {
diacriticLetters_ = QString::fromUtf8("ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ");
noDiacriticLetters_ << "S"<<"OE"<<"Z"<<"s"<<"oe"<<"z"<<"Y"<<"Y"<<"u"<<"A"<<"A"<<"A"<<"A"<<"A"<<"A"<<"AE"<<"C"<<"E"<<"E"<<"E"<<"E"<<"I"<<"I"<<"I"<<"I"<<"D"<<"N"<<"O"<<"O"<<"O"<<"O"<<"O"<<"O"<<"U"<<"U"<<"U"<<"U"<<"Y"<<"s"<<"a"<<"a"<<"a"<<"a"<<"a"<<"a"<<"ae"<<"c"<<"e"<<"e"<<"e"<<"e"<<"i"<<"i"<<"i"<<"i"<<"o"<<"n"<<"o"<<"o"<<"o"<<"o"<<"o"<<"o"<<"u"<<"u"<<"u"<<"u"<<"y"<<"y";
}
QString output = "";
for (int i = 0; i < s.length(); i++) {
QChar c = s[i];
int dIndex = diacriticLetters_.indexOf(c);
if (dIndex < 0) {
output.append(c);
} else {
QString replacement = noDiacriticLetters_[dIndex];
output.append(replacement);
}
}
return output;
}
Note that noDiacriticLetters_ needs to be a QStringList since some characters with diacritic marks can match to two single characters. For example œ => oe
Your question is a bit misleading. You seem to want to do more than merely remove diacritical marks (œ is a ligature letter without diacritics). I guess you want to turn any Unicode string into a roughly corresponding ASCII string?
For diacritics, you could perform a decomposing Unicode normalization (NFD or NFKD, depending on your specific needs) and then remove all characters of the "Mark" categories (QChar::Mark_NonSpacing, QChar::Mark_SpacingCombining and QChar::Mark_Enclosing).
For everything else (e.g. œ), I don't know of a generic solution. Create a look-up table with all your desired replacements and then search and replace (see Laurent's answer).
A partial solution is to use QString::normalized, than remove the special characters.
QString test = QString::fromUtf8("éçàÖœ");
QString stringNormalized = test.normalized (QString::NormalizationForm_KD);
stringNormalized.remove(QRegExp("[^a-zA-Z\\s]"));
This is however a partial solution because it will not convert "œ" into "oe".
There is crude way to partial solve your problem (just accents, but not ligatures such as "oe").
QString title=QString::fromUtf8("éçàÖ");
qDebug("%s\n", title.toLocal8Bit().data());
I have problems with inserting string variable inside text.
string p="http://www.google.com" ;
system("c:\\progra~1\\intern~1\\iexplore.exe \"http://www.google.com\"");
I need a way to use p instead of "http://www.google.com\"
I tried
system("c:\\progra~1\\intern~1\\iexplore.exe \%p\"");
but it doesn't work. I'm not very good with strings so probably that's the prob.
In C++ you can use the + operator to concatenate strings:
system((std::string("c:\\progra~1\\intern~1\\iexplore.exe ") + p).data());
In this case this is a bit hard to read, so you're better off creating the string before hand.
A better way would be to use stringstream:
#include <sstream>
std::stringstream sstr;
std::string p = "http://www.google.com";
sstr << "c:\\progra~1\\intern~1\\iexplore.exe " << p;
system(sstr.str().data());
Lets assume c#
string blammy = #"c:\progra~1\intern~1\iexplore.exe";
string finalAnswer;
string pikaPika = #"http://www.google.com";
finalAnswer = blammy + " " + pikaPika;
system(finalAnswer);