19.3.2 Extracting characters
This subsection gives an example of extracting only alphanumeric characters from the character string 0123-4567-89AB-CDEF and outputs the results to RecDFile.log.
- Organization of this subsection
(1) Coding example
strStrName = "0123-4567-89AB-CDEF"; // Original string
strSearchStr = "-"; // Search string
nStartPos = 0;
while(TRUE)
// Gets the length of string to be extracted.
nLength = AIT_FindSubStr(strStrName, strSearchStr, nStartPos);
if (nLength == -1)
// Sets the string to be extracted last.
strSubString = strStrName;
AIT_LogMessage("strSubString = " + strSubString);
// Ends extraction of strings.
break;
else
// Extracts a string.
if (!AIT_GetSubStr(strSubString, strStrName, nStartPos, nLength))
AIT_LogMessage("AIT_GetSubStr failed");
break;
else
AIT_LogMessage("strSubString = " + strSubString);
endif;
// Deletes the extracted string from the original string.
strStrName = AIT_StrLTrim(strStrName, strSubString);
strStrName = AIT_StrLTrim(strStrName, strSearchStr);
strSubString = "";
endif;
loop;
// Value of strStrName changes from that before processing.
AIT_LogMessage("strStrName = " + strStrName);
(2) Results
The following shows the results output to RecDFile.log.
strSubString = 0123 strSubString = 4567 strSubString = 89AB strSubString = CDEF strStrName = CDEF