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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STRFIND

Status
Not open for further replies.

Volkmaniac

Technical User
Mar 19, 2003
104
US
I'm using some code from a countitems script I took off this site. I was wondering if there was a way you can "match exact case" The problem I'm having is that it will count "CAP1" (below) twice because it's counting every instance of the characters. I tried reading the string length but it kept coming up as NULL. Is there anything I can do to ensure that the exact match will only be counted?

fopen 1 fname read text

While not feof 1
fgets 01 sLine

If strfind sLine "CAP1" MATCHCASE
A++
Endif
If strfind sLine "CAP1X" MATCHCASE
B++
Endif

strfmt Output "CAP1: %d" A
Termwrites Output
Termwrites "`n`r"
strfmt Output "CAP1X: %d" B
Termwrites Output
Termwrites "`n`r"
 
If the exact and entire string is CAP1 or CAP1X, then you could use the strcmp command instead of strfind. Strcmp will tell you if the strings match exactly, while strfind just tells you if one string appears in another. Here's an example from the help file that shows how it works:

proc main
string FirstStr, SecondStr ; Two strings to compare.

FirstStr = "First" ; Assign arbitrary value to first.
SecondStr = "Second" ; Assign arbitrary value to second.
if strcmp FirstStr SecondStr ; See if the two strings match.
usermsg "The two strings are identical."
else
usermsg "The two strings are different."
endif
endproc

Another option is to change your script so that you have an elseif statement that checks first for CAP1X and then for CAP1. It would look something like this:

If strfind sLine "CAP1" MATCHCASE
A++
elseif strfind sLine "CAP1X" MATCHCASE
B++
Endif

aspect@aspectscripting.com
 
Thanks,

It worked pretty well using this:

If strncmp sLine "CAP1" 4
GO++
else

Except I started the comparison on the longest strings (some had up to 10) and I worked my way down.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top