M_csfilename = csstr. Right (csstr. getlength ()-csstr. reversefind ('\')-1 );
Remove the. dll file XXXX. dll
Method 1,
Char STR [] = "XXXX. dll"
Char * P;
P = strrchr (STR ,'.');
* P = 0;
Method 2,
Cstring STR = "XXXX. dll ";
Int n = Str. reversefind ('.')
STR = Str. Left (Str. getlength ()-N-1 );
Example 2: (csdn)
Obtain the first '? Character before'
Method 1
Cstring m_char, m_disp;
M_disp = "jadfueiuajdf? ";
M_char = "? ";
If (! M_char.isempty ())
{
Int Index = m_disp.find (m_char );
M_disp = m_disp.right (m_disp.getlength ()-index-1 );
}
Only m_disp is returned.
Method 2
Cstring temp = The. m_bb;
Cstring reslut = temp. Left (temp. Find ("? ")-1 );
Example 3: (csdn)
A cstring Class Object m_strreceivemodem = {ats0 = 2
OK
$03 #}
How to intercept a string starting from $
Method 1
Cstring m_strreceivemodem;
Int NPOs = m_strreceivemodem.find ('$ ');
If (NPOs> = 0)
{
Cstring ssubstr = m_strreceivemodem.mid (NPOs); // contains $. If you do not want to include NPOs + 1
}
Method 2
Cstring m_strreceivemodem;
Int NPOs = m_strreceivemodem.find ('$ ');
If (NPOs> = 0)
{
Cstring ssubstr = m_strreceivemodem.right (strreceivemodem. getlength ()-NPOs );
}
And mid (INT nfirst, int nsize)
What should I do if I define a string cstring to be found to intercept this string ???
Cstring = "ABCDE base64 baaaaa"
The strings after base64 must be retained. How can this problem be solved ????
Now that you know the length of the string and where the separator is located, you can use the cstring: Right () function to obtain the last half of the string, as shown below:
Cstring STR = "ABCDE base64 baaaaa ";
STR = Str. Right (6); // obtain the string consisting of the last six characters of STR on the right side of the equation and assign it to str.
If you do not know the exact position of the split point, you can use the following function to find it:
Cstring: Find () // 1
Cstring: findoneof () // 2
Function 1 has the following prototypes:
Int find (tchar ch) const;
Int find (lpctstr lpszsub) const;
Int find (tchar CH, int nstart) const;
Int find (lpctstr lpszsub, int nstart) const;
The prototype of function 2 is:
Int findoneof (lpctstr lpszcharset) const;
After finding the separator, You can intercept it.
Cstring: Right (int n) is opposite to cstring: Left (int n). It is used to intercept the first n characters of a string.
Cstring STR = "ABCDE base64 baaaaa ";
Cstring findstr = "base64 ";
Cstring mystr;
Int K = Str. Find (findstr) + findstr. getlength ();
Mystr = Str. Right (Str. getlength ()-k );
Cstring Cs;
Returns the value of CS. Left (int x) X on the left;
Returns the value of CS. Right (int x) X to the right;
CS. getlength ();;
In my opinion, if you use the above three functions, any character segment in the cstring will be truncated.
Afxmessagebox (mystr );
String: D: \ cr14 \ Pe \ mfc_pe \ debug \ mfc_pe.exe
Interception target: mfc_pe.exe
Method: m_csfilename = csstr. Right (csstr. getlength ()-csstr. reversefind ('\')-1 );