Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for Carriage Returns, etc with CString

Status
Not open for further replies.

One2b

Programmer
May 29, 2003
14
US
I am attempting to find a Carriage Return, a Line Feed, and/or Tabs in a CString. I am trying to use the CString::Find function, but am not sure what the correct parameter it takes. I thought \015, \102, \011, would be find however, it says that I have an illegal escapte sequence. Can anyone tell me how i get CString::Find to search for CR, LF, or Tabs? Thx
 
as far as I know:
\n -CR
\t -TAB

... the signs you need for output

but I am not sure, try it

Greetings Andreas
 
ya i already tried those....the prob is that it says they are illegal escape sequences. I am not sure how CString::Find looks for carriage returns etc.
 
Try:
'\r' carriage return
'\n' line feed
'\t' tab

This should work
Ex.
Code:
CString a;

...

int pos= a.Find('\r',0);
[\code]

If you want to find just one of the characters (don't care which) use:

[code]
int pos = a.FindOneOf("\r\n\t");
[\code]

Hope this helps...
 
Hmm maybe my problem lies somewhere else...do u mind lookin at my code? I am tryin to remove all comments from this CString (i.e anywhere I see a ;;).

CString CParamString::excludeComments(CString &s)
{
TRACE("Entering excludeComment(CString &s)\n");
int iSLength = s.GetLength();
int iSFindSemiColons = s.Find(";;");
int iSFindCR = (s.Right(iSFindSemiColons)).Find('\n'); //Find a Carriage Return to find end of line
int iSFindTab = (s.Right(iSFindSemiColons)).Find('\t'); //Find a Tab to find end of line
//TRACE("This is a Carriage Return: %d\n", );
TRACE("iSLength: %d\n", iSLength);
TRACE("iSFindSemiColons: %d\n", iSFindSemiColons);
TRACE("iSFindCR: %d\n", iSFindCR);
TRACE("iSFindTab: %d\n", iSFindTab);

if(-1 != iSFindSemiColons) //If enter here, comments have been found
{
cszTmp += s.Left((iSLength - iSFindSemiColons)); //Add everything before the comments (ie ;;) to the CString
if(-1 != iSFindCR) //If enter here the end of the line is a Carriage Return and use everything past it to search for next set of comments
{
excludeComments(s.Right(iSFindCR));
}
if(-1 != iSFindTab) //If enter here there was a tab, check everything past it for comments
{
excludeComments(s.Right(iSFindTab));
}
else //If enter here neither tab nor carriage return were at the end, so check
{
excludeComments(s);
}
}
return cszTmp += s; //Done searching for comments, return final answer (ie, a CString with no comments)
}
 
if your cstring is n characters long and you find CR at
position p I don't think you can say s.Right(p). Should be
s.Right(n-p). Using p maybe you can say s.Mid(p) but I'm
not familiar with these cstring-functions. I prefer using
char with pointers for parsing text.
Once again : check those right-functions !
hope this helps
 
ya i realized i need to use mid now instead....but i think im gettin there. I got a ways to go, but im closer then i was when i came into work this morning hehe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top