View previous topic :: View next topic |
Author |
Message |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 20, 2009 4:55 pm Post subject: [?] Filtering out character '\n' in a string |
|
|
Here's Irwin's code..
Code: | VOID FilterString(__in_z LPCTSTR lpcszFilterString, __in TCHAR tch, __out_z LPTSTR lpszBuffer)
{
TCHAR tchUpper = _totupper(tch);
UINT i = 0;
for (; i < _tcslen(lpcszFilterString); i++)
if (_totupper(lpcszFilterString[i]) != tchUpper)
lpszBuffer[i] = lpcszFilterString[i];
lpszBuffer[i] = _T('\0');
} |
So I used..
Code: | FilterString(szScript, '\t', szScriptAll); |
szScriptAll should have been "nn", but instead, it's..
I can't filter '\n' for some reason, but I can filter every other character. Help?
|
|
Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Fri Mar 20, 2009 5:16 pm Post subject: |
|
|
Code: | char* FilterCharacter( char* szSrc, const char* Filter ) {
char* szReturn = new char[500];
char* szToken = strtok( szSrc, Filter );
while( szToken != NULL ) {
strcat( szReturn, szToken );
szToken = strtok( NULL, Filter );
}
return szReturn;
} |
I have no idea if it works, i coded it off the top of my head.
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Fri Mar 20, 2009 6:06 pm Post subject: |
|
|
Irwin's posted code was wrong. Here's the fix that i applied:
Code: | VOID FilterCharacter(__in_z LPCTSTR lpcszFilterString, __in TCHAR tch, __out_z LPTSTR lpszBuffer)
{
TCHAR tchUpper = _totupper(tch);
UINT i = 0, pos = 0;
for (; i < _tcslen(lpcszFilterString); i++)
if (_totupper(lpcszFilterString[i]) != tchUpper)
lpszBuffer[pos++] = lpcszFilterString[i];
lpszBuffer[pos] = _T('\0');
} |
FilterCharacter("t\testt\tes\tstt\test", '\t', buffer);
and
FilterCharacter("tes\nts\nttes\nt", '\n', buffer);
work perfectly fine.
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 20, 2009 6:25 pm Post subject: |
|
|
Hmm, interesting.. in a multi-line text box, is a new line (hitting the return key) interpreted as a '\n'?
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Fri Mar 20, 2009 6:28 pm Post subject: |
|
|
talker0 wrote: | Hmm, interesting.. in a multi-line text box, is a new line (hitting the return key) interpreted as a '\n'? |
Probably.. convert the string to hex and check.
\n = 0x10 = Line Feed
|
|
Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Fri Mar 20, 2009 11:40 pm Post subject: |
|
|
It may be represented by \r\n instead, and that could be the problem.
|
|
Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Mar 21, 2009 10:39 am Post subject: |
|
|
It's represented as \r\n.
_________________
8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sat Mar 21, 2009 12:23 pm Post subject: |
|
|
Yup.. worked after I filtered out both \r and \n. Thanks
|
|
Back to top |
|
 |
|