高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】getting contents from oddbmte
getting contents from oddbmtext
getting contents from oddbmtext
hi,
i am looking for functions to get each line of text from oddbmtext.contents(). i wrote some logic to do this. but it doesn't work properly. my code is as follows:
.........
strcpy(contents, pmtext->contents());
char *token = strtok(contents, pmtext->linebreak());
while( token != null )
{
strcpy(set.content, token);
sets.push_back(set);
// go to next line of text
token = strtok( null, pmtext->linebreak());
}
...
i can see the pmtext->contents() seems like "aaa\pbbb\bccc", and pmtext->linebreak() seems like "\p". but the tokens returning are "aaa", "pbbb", "bccc".
but if i do this as follows, it works.
.........
strcpy(contents, "aaa\pbbb\bccc");
char *token = strtok(contents, "\p");
while( token != null )
{
strcpy(set.content, token);
sets.push_back(set);
// go to next line of text
token = strtok( null, "\p");
}
...
so i guess the return values of pmtext->contents() and pmtext->linebreak() are not what they look like.
is there a way to get these line of text from the lib?
thanks..
the character '\' starts escape sequence in c++ code. pmtext->linebreak() returns string with two characters '\' and 'p' or in other words in c++ code it will be string "\\p". the mtext string contains same two characters.(for example: it is "aaa\\pbbb" in c++ code). try use strstr() function. note paragraphbreak()("\\p") is line break also.
--
best regards,
sergey zaitcev
it works. thanks for the help.
maybe it's easier to use oddbmtext::explodefragments() instead of parsing the contents manualy?
sergey slezkin
|