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

Comparing a string of numbers to a letter

Status
Not open for further replies.

programmingiscool

Programmer
Sep 8, 2011
1
US
Hi all,

I am new to Procomm Scripting and I was wondering if anyone could help me with this task. I am currently trying to compare a each character in string to a all the letters in the alphabet and display an error message if the comparison is true.

For example:

My string is "123456789J" and I want to check if 1 does not equal to A-Z and then continue to do that for 2,3,4, and so on. Please help and let me know how I can do this. Thank you very much!
 
Take a look at strchr

proc main
string TextStr ; Text string to search.

TextStr = "1 2 3 4 5 6" ; Assign value to search string.
if strchr TextStr '5' ; Look for target char in string.
usermsg "Search string contains target char!"
else
usermsg "Search string doesn't contain target char!"
endif
endproc
 
strcspn should do the trick for you. Below is a sample script I took from the ASPECT help file and modified a bit. strcspn returns success if a match is found, so you would want to pop up an error message at the comment in the script below since it would indicate that your string had a letter in it.

proc main
string Text1 ; First text string.
string Text2 ; Second text string.
; are the same.
Text1 = "123456789J"
Text2 = "ABCDEFGHIJKLMONPQRSTUVWXYZ"
strcspn Text1 Text2 ; Find a contained character
if success
;remediation efforts go here...
endif
endproc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top