|
|
Comments and Discussions
|
|
 |

|
Good day Johan,
It's me again.. Can u please help to show me how to append a string in an exist file with a space before it append.
My code seems were not able to solve this. I even tried to have a "" string appended before the words that i want to append but it will be still the same. Below are my codes.
CString space = "";
CString s = "123";
appsec.AppendFile(recfile,space);
appsec.AppendFile(recfile,s);
Results like this
15:22:02123
It did not have a space between the existed line in the file. Can u please help to advice?
Thanks
Zamani
|
|
|
|

|
space is declared as "", that is, it is no space at all. It should be " ".
|
|
|
|

|
Thanks!! it worked
best regards
z
|
|
|
|

|
Hello Johan,
Thanks for the fast response on the last question, anyway i have another thing that need help from you.
From the classes that you had wrote, is it possible that i can differentiate to 2 different string from two words in a single txt file.
For eg,
inside my txt file the are 2 words in a single line
eg
stone rock
Can i read this line and convert this "stone" and "rock" to 2 differenct CString?
CString a = stone CString b = rock.
Really appreciate if u can let me know.
Thank you very much.
Rgds
|
|
|
|

|
You'll want to call CString::Find to find the space, CString::Left and CString::Mid to split it.
|
|
|
|

|
Thanks for the sharing. It worked.
Rgds
CN
|
|
|
|

|
Hello,
BTW, the class is very great. Anyway, i have problem when reading the string from the txt file related to the what it read. Seems like i always have this [] symbol at the end of the string. I don't know how to get the string without this. FOr eg here is the string that i had
20080219140631.bmp[] ....
Can u please help if you have any idea?
thanks
|
|
|
|

|
This looks like a single little box - if so, this is an unprintable character. It is most likely a carriage return. If so, you'll get rid of it by calling the CString member TrimRight on the string, so: sSomeString.TrimRight();
|
|
|
|

|
Hellooo,
yeah, you're correct and it did very well after yr suggestion. Thank you very much for yr great help..
thanks
|
|
|
|

|
how?
everything ive tryed has endedup being 1 line i guess it keeps overwriting it
if (m_useall.GetCheck() == 1)
{
chrcount++;
m_wordcount++;
number = chrcount;
file.WriteTextFile(filename, number);
m_currentword = number;
UpdateData(FALSE);
}
im using that in a loop works fine but it only writes on 1 line
i need it to write line after line.
and i cant use an array.
|
|
|
|

|
What I've seen in the help that the article submitter has written is that the function that you are using writes the entire file, and overwrites it if it exists.
I suggest you to use a different function or to store all the data in a CString and then, after the loop calling that function in order to store all the content at one time.
Hope this helps.
|
|
|
|
|

|
Can't really say why CFile crashes, but an idea is - self-evident really - to write the file in smaller chunks.
|
|
|
|

|
Hi,
I have a CString to which I am appending a lot of strings with \n character ate the end of each string. I want to write to a file at the last possible moment. How would I break this up at the last moment. Or should I store the strings in a CStringArray and then write each of these into a file. I dont want to leave the handle to the file open for a long time as I have a lot of strings to write to the file.
Nikhil
|
|
|
|

|
CStringArray sounds like a good idea.
|
|
|
|

|
Hi,
I fixed the problem. Now am writing as I genetrate text for the output file.
Now, heres what I find wierd. I have an out put file with delimiters, spaces, tabs etc, and tags. Looks like XML. This is the file I could not write.
I also have a log window which is an edit box which shows the operations I perform on the XML file before writing. I apped each displayed string into a CString.
I was using the same CFile class to write the XML output file and the log file.
Both can exceed 5Mb. The log file is written even if it is 10Mb. The XML like file is not written. Wierd.
Nikhil
|
|
|
|

|
If you are not storing the log data in a CString before writing, then it sounds like CString is the culprit rather than CFile.
|
|
|
|

|
If the author wants, I'll supply a version that creates a .bak file before overwriting.
--hsm
hsmyers@sdragons.com
|
|
|
|

|
I'd be delighted! Use the e-mail-link at the bottom of this message, then I'll incorporate it into the article.
|
|
|
|

|
I wasn't thinking and sent the .zip file to your email. Let me know if you got and if not I'll put it into the reply...
--hsm
|
|
|
|

|
Great class. Thanks...
DEBUGGING : Removing the needles from the haystack.
|
|
|
|

|
Thanks for the feedback. It's a little timesaver, isn't it
|
|
|
|

|
Johan Rosengren wrote: Thanks for the feedback.
Welcome.
Indeed it is a time saver, I had to however add a member function to set the defaults (as I add a member variable in my class and just reuse it).
SetDefaults(const CString& ext, const CString& eol )
{
Same as the constructor
}
Might not be a bad addition.
DEBUGGING : Removing the needles from the haystack.
|
|
|
|

|
I'll keep this in mind for any future updates - I do a reread of all comments for all articles since their last update, ticking of any improvements that needs to be done
|
|
|
|

|
Johan Rosengren wrote: I'll keep this in mind for any future updates
Okay, Thanks again.
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A small helper class for reading, writing and appending to/from text files.
| Type | Article |
| Licence | Public Domain |
| First Posted | 21 Mar 2004 |
| Views | 130,597 |
| Bookmarked | 62 times |
|
|