Click here to Skip to main content
15,891,976 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Eval Copy Pin
John M. Drescher19-Aug-04 4:53
John M. Drescher19-Aug-04 4:53 
GeneralRe: Eval Copy Pin
gamitech19-Aug-04 11:29
gamitech19-Aug-04 11:29 
GeneralRe: Eval Copy Pin
shiraztk19-Aug-04 20:12
shiraztk19-Aug-04 20:12 
GeneralIUnknown casting Pin
RChin19-Aug-04 0:34
RChin19-Aug-04 0:34 
GeneralRe: IUnknown casting Pin
Antti Keskinen19-Aug-04 0:55
Antti Keskinen19-Aug-04 0:55 
GeneralRe: IUnknown casting Pin
RChin19-Aug-04 1:16
RChin19-Aug-04 1:16 
GeneralCString Pin
Johnny Peszek19-Aug-04 0:24
Johnny Peszek19-Aug-04 0:24 
GeneralRe: CString Pin
Antti Keskinen19-Aug-04 1:16
Antti Keskinen19-Aug-04 1:16 
Answer: basic math, pen and a paper.

Following your description, if you'd need to delete the last 5 lines, this means that you'd need to delete so many characters starting from the end that you'd reach the fifth '\n' character. The lines in a CString object are stored sequentically, with line changes denoted as '\n' and the end of the string as '\0'.

An example. Consider that your arbitary string is structured as follows "111111111111\n22222222222\n333333333333\n44444444444\n555555555555\n6666666666666\n77777777777\0".

Now, if you'd need to delete the last two lines, you'd first need to determine how many lines there are on the string. This means finding how many '\n' characters are found. The line quantity is this added with 1 (last line doesn't have a '\n'). When you had this amount, in this case, 7, and would need to delete 2 lines, it would leave us 4 '\n' characters, right ? So, let's search until we find the fifth '\n' character. After we get it's index, we delete characters from the string, starting from this index. Thus, the last fifth '\n' is replaced by a '\0', and all remaining characters are deleted.

Finding the amount of '\n' is easy: start from the beginning, find the first one. Then start again, from the index returned by the first search plus one. By using this recursive search method, you can run through the string and find out how many line changes you have.

It's pretty straigthforward, although might feel difficult at first. But the quicker you start, the quicker you get it done Smile | :)

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: CString Pin
Johnny Peszek19-Aug-04 1:22
Johnny Peszek19-Aug-04 1:22 
GeneralRe: CString Pin
V.19-Aug-04 1:35
professionalV.19-Aug-04 1:35 
GeneralRe: CString Pin
Johnny Peszek19-Aug-04 1:43
Johnny Peszek19-Aug-04 1:43 
GeneralRe: CString and FYI Pin
V.19-Aug-04 2:18
professionalV.19-Aug-04 2:18 
GeneralUTF-8 to Unicode Pin
muthukumar_pandian19-Aug-04 0:19
muthukumar_pandian19-Aug-04 0:19 
GeneralRe: UTF-8 to Unicode Pin
Blake Miller20-Aug-04 4:55
Blake Miller20-Aug-04 4:55 
GeneralRe: UTF-8 to Unicode Pin
anderslundsgard30-Aug-04 2:07
anderslundsgard30-Aug-04 2:07 
GeneralRe: UTF-8 to Unicode Pin
Blake Miller30-Aug-04 6:18
Blake Miller30-Aug-04 6:18 
Generalcoledatetime formating time Pin
prasad_som19-Aug-04 0:09
prasad_som19-Aug-04 0:09 
GeneralRe: coledatetime formating time Pin
RChin19-Aug-04 0:44
RChin19-Aug-04 0:44 
GeneralRe: coledatetime formating time Pin
David Crow19-Aug-04 2:44
David Crow19-Aug-04 2:44 
Generalcreating help file Pin
Anonymous18-Aug-04 22:51
Anonymous18-Aug-04 22:51 
GeneralRe: creating help file Pin
David Crow19-Aug-04 2:54
David Crow19-Aug-04 2:54 
QuestionEfficient Thread Synchronization Object? Pin
aufeuer18-Aug-04 21:37
aufeuer18-Aug-04 21:37 
AnswerRe: Efficient Thread Synchronization Object? Pin
valikac19-Aug-04 5:56
valikac19-Aug-04 5:56 
AnswerRe: Efficient Thread Synchronization Object? Pin
gamitech19-Aug-04 11:41
gamitech19-Aug-04 11:41 
GeneralRe: Efficient Thread Synchronization Object? Pin
aufeuer19-Aug-04 14:32
aufeuer19-Aug-04 14:32 

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.