Click here to Skip to main content
16,016,562 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: std::string weird behaviour??¿?¿ Pin
Dean Goodman22-May-02 10:57
Dean Goodman22-May-02 10:57 
GeneralRe: std::string weird behaviour??¿?¿ Pin
Carlos Sánchez García22-May-02 23:12
Carlos Sánchez García22-May-02 23:12 
GeneralTwo questions: CFileDialog & vector Pin
Dean Goodman22-May-02 9:59
Dean Goodman22-May-02 9:59 
GeneralRe: Two questions: CFileDialog & vector Pin
Chris Losinger22-May-02 10:01
professionalChris Losinger22-May-02 10:01 
GeneralRe: Two questions: CFileDialog & vector Pin
Dean Goodman22-May-02 10:32
Dean Goodman22-May-02 10:32 
GeneralRe: Two questions: CFileDialog & vector Pin
Joaquín M López Muñoz22-May-02 11:08
Joaquín M López Muñoz22-May-02 11:08 
GeneralExtended MAPI vs. Outlook Object Model Pin
22-May-02 9:22
suss22-May-02 9:22 
GeneralInserting strings Pin
Emearg22-May-02 8:58
Emearg22-May-02 8:58 
Hey...

I'm trying to make a simple little program that takes a string, searches for that string in a different string, and once that string is found, replace it with a different string. I want it to do this to the end of the string.

I'm kinda stuck right now, cause I don't know how to use the CString::Insert() and Find() functions right. I had a function that Replace()'d everything, but the problem was that I was trying to replace "\r\n" with "<br>\r\n", so it kept looping around and inserting till I had something that looked like: "Hello World<br><br><br><br><br><br><br><br><br><br>\r\n".

Also, in the replace function I'm using it uses lstrlen() functions, and I'm not *exactly* sure what those do.

If someone could point me to an article where it talks about things like this, or gave me some advice in a reply, I'd be very thankful.

Thanks, Emearg


The function I'm using:

CString CMFC2Dlg::Replace(LPCTSTR instr, LPCTSTR oldstr, LPCTSTR newstr)
{
CString output(instr);
CString input_lower(instr);
CString oldone_lower(oldstr);
input_lower.MakeLower();
oldone_lower.MakeLower();

int pos=0;
while ( (pos=input_lower.Find(oldone_lower,pos))!=-1 )
{
input_lower.Delete( pos, lstrlen(oldstr) );
input_lower.Insert( pos, newstr );

output.Delete( pos, lstrlen(oldstr) );
output.Insert( pos, newstr );
}

return output;
}


Called by:
LogConvert = Replace(LogString, "\r\n", "<br>\r\n");
GeneralRe: Inserting strings Pin
Carlos Antollini22-May-02 9:25
Carlos Antollini22-May-02 9:25 
GeneralRe: Inserting strings Pin
Dean Goodman22-May-02 10:02
Dean Goodman22-May-02 10:02 
GeneralRe: Inserting strings Pin
Emearg23-May-02 5:41
Emearg23-May-02 5:41 
GeneralSearching for files in a specific folder and it's subfolders. Pin
redeemer22-May-02 8:58
redeemer22-May-02 8:58 
GeneralRe: Searching for files in a specific folder and it's subfolders. Pin
Chris Losinger22-May-02 9:07
professionalChris Losinger22-May-02 9:07 
GeneralRe: Searching for files in a specific folder and it's subfolders. Pin
redeemer22-May-02 9:09
redeemer22-May-02 9:09 
GeneralRe: Searching for files in a specific folder and it's subfolders. Pin
Chris Losinger22-May-02 9:12
professionalChris Losinger22-May-02 9:12 
GeneralRe: Searching for files in a specific folder and it's subfolders. Pin
Mazdak22-May-02 9:21
Mazdak22-May-02 9:21 
GeneralRe: Searching for files in a specific folder and it's subfolders. Pin
Martin Ziacek22-May-02 9:24
Martin Ziacek22-May-02 9:24 
GeneralWould it work if i did this: Pin
redeemer22-May-02 9:54
redeemer22-May-02 9:54 
GeneralAVIFile & audio Pin
Zizilamoroso22-May-02 8:33
Zizilamoroso22-May-02 8:33 
GeneralSettling Listview subitem color Pin
22-May-02 7:51
suss22-May-02 7:51 
GeneralRe: Settling Listview subitem color Pin
Dana Holt22-May-02 9:36
Dana Holt22-May-02 9:36 
Generalpass variables from an MFC app to external program Pin
kevinsky22-May-02 7:50
kevinsky22-May-02 7:50 
GeneralRe: pass variables from an MFC app to external program Pin
Chris Losinger22-May-02 9:09
professionalChris Losinger22-May-02 9:09 
Generaladobe acrobat form fields Pin
Mr. Bill22-May-02 6:38
Mr. Bill22-May-02 6:38 
GeneralSorting CListCtrl columns on a mouse click Pin
Anton A. Loukine22-May-02 6:37
Anton A. Loukine22-May-02 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.