C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
finding a singular W in a line of text Posted by gsumner on 16 Apr 2006 at 11:14 AM
Hi guys,

Basically I am indexing through lines of text in a text file.

I am looking to delete lines of text with a singular W in it with a space at either side. ie " W "

I would delete this line if I could find it:-

The cat sat on the W mat.

The lines of text are read in as AnsiStrings

AnsiString LineToCheck;

if (LineToCheck.AnsiPos(" W ")>0)
{
Blah Blah Blah
}

// this should find the above line but is doesn't. Any idea how I can overcome this ??

Thanks
Graham
Report
Re: finding a singular W in a line of text Posted by Ed Hall on 16 Apr 2006 at 2:14 PM
: Hi guys,
:
: Basically I am indexing through lines of text in a text file.
:
: I am looking to delete lines of text with a singular W in it with a space at either side. ie " W "
:
: I would delete this line if I could find it:-
:
: The cat sat on the W mat.
:
: The lines of text are read in as AnsiStrings
:
: AnsiString LineToCheck;
:
: if (LineToCheck.AnsiPos(" W ")>0)
: {
: Blah Blah Blah
: }
:
: // this should find the above line but is doesn't. Any idea how I can overcome this ??
:
: Thanks
: Graham
:

Can you use strstr() to check for a substring in LineToCheck?

Take Care,
Ed


Report
Re: finding a singular W in a line of text Posted by gsumner on 16 Apr 2006 at 3:44 PM
: : Hi guys,
: :
: : Basically I am indexing through lines of text in a text file.
: :
: : I am looking to delete lines of text with a singular W in it with a space at either side. ie " W "
: :
: : I would delete this line if I could find it:-
: :
: : The cat sat on the W mat.
: :
: : The lines of text are read in as AnsiStrings
: :
: : AnsiString LineToCheck;
: :
: : if (LineToCheck.AnsiPos(" W ")>0)
: : {
: : Blah Blah Blah
: : }
: :
: : // this should find the above line but is doesn't. Any idea how I can overcome this ??
: :
: : Thanks
: : Graham
: :
:
: Can you use strstr() to check for a substring in LineToCheck?
:
: Take Care,
: Ed

:
:
Hi Ed, It would appear not. I think strstr() is for character strings and at this stage I cannot convert my ansistring LineToCheck into a character string to do the check. I can't understand why AnsiPos or Pos won't find the " W " correctly.

Graham
Report
Re: finding a singular W in a line of text Posted by Ed Hall on 17 Apr 2006 at 7:10 AM
: Hi Ed, It would appear not. I think strstr() is for character strings and at this stage I cannot convert my ansistring LineToCheck into a character string to do the check. I can't understand why AnsiPos or Pos won't find the " W " correctly.
:
: Graham
:

Is it possible the case of the W or the spaces are being read oddly? Have you tried seaching for other substrings? You've probably tried these methods, but I'm trying to help from afar. How about looking for the hex values of the spaces - \x20W\x20, as referenced in the first link below. I know you've probably also scoured the web, but here are some Borland pages, if they may help:

http://support.borland.com/thread.jspa?threadID=2046&tstart=90
http://support.borland.com/thread.jspa?messageID=6024
http://www.functionx.com/bcb/topics/strings.htm

The last one has to do with C++ Builder, but maybe there's something to trigger a solution.

Sorry I can't be of more help. Good luck with it.

Take Care,
Ed


Report
Re: finding a singular W in a line of text Posted by gsumner on 17 Apr 2006 at 11:48 AM
: : Hi Ed, It would appear not. I think strstr() is for character strings and at this stage I cannot convert my ansistring LineToCheck into a character string to do the check. I can't understand why AnsiPos or Pos won't find the " W " correctly.
: :
: : Graham
: :
:
: Is it possible the case of the W or the spaces are being read oddly? Have you tried seaching for other substrings? You've probably tried these methods, but I'm trying to help from afar. How about looking for the hex values of the spaces - \x20W\x20, as referenced in the first link below. I know you've probably also scoured the web, but here are some Borland pages, if they may help:
:
: http://support.borland.com/thread.jspa?threadID=2046&tstart=90
: http://support.borland.com/thread.jspa?messageID=6024
: http://www.functionx.com/bcb/topics/strings.htm
:
: The last one has to do with C++ Builder, but maybe there's something to trigger a solution.
:
: Sorry I can't be of more help. Good luck with it.
:
: Take Care,
: Ed

:
:
Thankyou Ed,
Headache over. Never worked with Hex before infact my programming is very rusty as I am updating a program I wrote years ago whilst studying c++. Thanks again for your help and patience, your a STAR!!
Regards
Graham
Report
Re: finding a singular W in a line of text Posted by tsagld on 18 Apr 2006 at 12:38 AM
: : : Hi Ed, It would appear not. I think strstr() is for character strings and at this stage I cannot convert my ansistring LineToCheck into a character string to do the check. I can't understand why AnsiPos or Pos won't find the " W " correctly.
: : :
: : : Graham
: : :
: :
: : Is it possible the case of the W or the spaces are being read oddly? Have you tried seaching for other substrings? You've probably tried these methods, but I'm trying to help from afar. How about looking for the hex values of the spaces - \x20W\x20, as referenced in the first link below. I know you've probably also scoured the web, but here are some Borland pages, if they may help:
: :
: : http://support.borland.com/thread.jspa?threadID=2046&tstart=90
: : http://support.borland.com/thread.jspa?messageID=6024
: : http://www.functionx.com/bcb/topics/strings.htm
: :
: : The last one has to do with C++ Builder, but maybe there's something to trigger a solution.
: :
: : Sorry I can't be of more help. Good luck with it.
: :
: : Take Care,
: : Ed

: :
: :
: Thankyou Ed,
: Headache over. Never worked with Hex before infact my programming is very rusty as I am updating a program I wrote years ago whilst studying c++. Thanks again for your help and patience, your a STAR!!
: Regards
: Graham
:

Is it possible that the string is in Unicode while you are searching ASCII or something? You can detect that with a hex editor.
Btw, ever tried using regular expressions? Little hard to bite at at first, but once you get the hang of it, they're great to search strings.


Greets,
Eric Goldstein
www.gvh-maatwerk.nl





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.