problems caused by file path escape characters
Requirements Problem Description: The file path is stored in the database when the ' \ ' is gone, such as: "D:\abc\123.jpg", after the escape of C + + language into the "D:\abc\123.jpg", in the database, the process of MySQL will be an escape, the result of ' becomes lost. Solution 1. Convert ' \ ' to ' \ '
The C + + string provides the Replace method to implement the replacement of the string, but the string does not implement the function of replacing a string in the string, which is what we're doing today.
First we understand the concept that string replaces all strings, substituting "21" for all "12" of the "12212" string, and what the result is.
Can be 22211, can also be 21221, sometimes the application of different scenarios, you will want to get different results, so both of the answers are implemented, the code is as follows:
' #include <string>
#include <iostream>
using namespace Std;
string& Replace_all (string& str,const string& old_value,const)
{
while (true)
String::size_type POS (0);
if ((Pos=str.find (Old_value))!=string::npos)
Str.replace (Pos,old_value.length (), new_value);
else break;
}
return str;
}
string& replace_all_distinct (string& str,const string& old_value,const)
{
For (String::size_type POS (0); Pos!=string::npos pos+=new_value.length ()) {
if ((Pos=str.find (Old_value,pos))!=string::npos)
Str.replace (Pos,old_value.length (), new_value);
else break;
}
return str;
}
int main ()
{
cout << Replace_all (String ("12212"), "a", "a" << Endl;
cout << replace_all_distinct (String ("12212"), "a", "a" << Endl;
}
' mysql keyword escape syntax
Like mode escape char
Select '/' like '/' escape '/'
Query result is 1
The value of a character as a field in a table is queried in the following way
Select name like '//' escape '/'
When Name= '/' The result is also 0.
It was later found that when executing a query in MySQL, if you defined the escape character, you should pay attention to some
1, before the query should be like special characters and SQL special characters to escape (_%? ' ").
2. If there are two consecutive escape characters in the escaped mode, you should also add an escape character (after the like special character) before mode, and if you add the first two consecutive escape characters, you should also escape with a special character.
That is, the query result is satisfied by changing the select name like '///' to ' escape '.
Of course, if the matching pattern is '/', it will become '/////' immediately after.