Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

strstr function not recognizing the character ±


Recommended Posts

I'm trying to catch special characters before they get posted, our MAS system won't allow them. 

 

I was successful with the characters "(", ")", and "°"

but when I put in the "±" it won't find it in the string.

Is there a way to make it recognize this character? 

Below is the code I used to check for parenthesis in the tool name. The code below that worked when I put "°" in there, but not "±"

Also, is there a way to run strstr on a list of characters without having to copy the code each time?

Or... would it be easier to get a list of the allowable characters and check against those. 

 

image.thumb.png.0c17d2bf5096dfddb2be7c154b9c34e1.png

Link to comment
Share on other sites

It appears that ± isn't in the post. I'm sure I would have tried it in my inspection program.

"DPRNT[***DISTANCE*", *drl_prm7$, [if drl_prm6$, "*TOL*+/-*", <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                 *drl_prm6$], "***]", e$

 

********************************PRINT***********************************

                spaces$ = 0

                 "POPEN", e$

                if s_popen_flg = 0,

                  [

                  s_popen, e$

                  s_popen_flg = 1

                  ]

                "DPRNT[]", e$

                "DPRNT[-----------------------------------------------------------]", e$

                "DPRNT[***", s_sav_comment , "***]", e$

                "DPRNT[***DISTANCE*", *drl_prm7$, [if drl_prm6$, "*TOL*+/-*", <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                 *drl_prm6$], "***]", e$

                "DPRNT[***RESULTS***DISTANCE*#138[24]***]", e$

                "DPRNT[-----------------------------------------------------------]", e$

                "DPRNT[]", e$

#                "PCLOS", e$

                spaces$ = sav_spc

#       ************************************************************************

Link to comment
Share on other sites

Instead of defining the ± in the "initialization", you may have to use the 'no2asc' function to make sure the correct bits are held in that variable.

Rather than repeating the code for each ASCII character, I'd try constructing a While Loop, and use a common "search string variable".

str_test : "" #empty string

str_warn : "" empty string

pmyblock

      str_test = no2asc(171) #Convert ASCII Code decimal value to Plus/Minus string representation

      pstr_test

       str_test = no2asc(40) #Convert ASCII Code decimal value to Left Paren string representation

      pstr_test

      str_test = no2asc(41) #Convert ASCII Code decimal value to Right Paren string representation

      pstr_test

 

 

pstr_test

      result = strstr(str_test, strtool$) #Test string for character assigned with no2asc

      if result <> 0,

        [

        str_warn = "BAD CHARACTER " + str_test + " FOUND IN strtool$ NAME." + no2ascii(13) + "FIX COMMENT AND REPOST!"

        result = mprint(str_warn)

        ]

 

 

 

  • Thanks 1
Link to comment
Share on other sites

Thanks Colin, I got it to work with the following code. Not pretty, but it does the trick.

str_testTool : "" #Empty String
str_warnTool : "" #Empty String

str_testComment : "" #Empty String
str_warnComment : "" #Empty String
str_CheckComment : "" #Empty String

ptoolCharacterCheck
    
      str_testTool = no2asc(33)            #no2asc(33) #Convert ASCII Code decimal value to ! string representation
      pstr_testTool
    
      str_testTool = no2asc(40)            #no2asc(40) #Convert ASCII Code decimal value to ( string representation
      pstr_testTool
     
      str_testTool = no2asc(41)            #no2asc(41) #Convert ASCII Code decimal value to ) string representation
      pstr_testTool
     
      str_testTool = no2asc(176)            #no2asc(176) #Convert ASCII Code decimal value to ° string representation
      pstr_testTool
      
      str_testTool = no2asc(177)            #no2asc(177) #Convert ASCII Code decimal value to ± string representation
      pstr_testTool
      
pOperationCommentCheck
    
      str_testComment = no2asc(33)            #no2asc(33) #Convert ASCII Code decimal value to ! string representation
      pstr_testComment
      
      str_testComment = no2asc(40)            #no2asc(40) #Convert ASCII Code decimal value to ( string representation
      pstr_testComment
      
      str_testComment = no2asc(41)            #no2asc(41) #Convert ASCII Code decimal value to ) string representation
      pstr_testComment
      
      str_testComment = no2asc(176)            #no2asc(176) #Convert ASCII Code decimal value to ° string representation
      pstr_testComment
      
      str_testComment = no2asc(177)            #no2asc(177) #Convert ASCII Code decimal value to ± string representation
      pstr_testComment

pstr_testTool

      result = strstr(str_testTool, strtool$) #Test string for character assigned with no2asc

      if result <> 0,
        [
        str_warnTool = "BAD CHARACTER " + str_testTool +  " FOUND IN" + " T#" + no2str(t$) + ", TOOL COMMENT IS "  + strtool$ + " NAME." + " PLEASE FIX COMMENT AND REPOST!"
        result = mprint(str_warnTool)
        ]
       
pstr_testComment
      str_CheckComment = scomm$
      result = strstr(str_testComment, str_CheckComment) #Test string for character assigned with no2asc
       
      if result <> 0,
       [
        str_warnComment = "BAD CHARACTER " + str_testComment + sbubbleinfo + " FOUND IN OPERATION " + drs_str(2,opnumber) + ", COMMENT IS "  + str_CheckComment + " PLEASE FIX COMMENT AND REPOST!"
        result = mprint(str_warnComment)
       ]

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...