Hello,
I have encountered some very strange behavior with the strRem(currentFile, _directory) method call, where currentFile is C:\Temp\TON20110919113920.CAB or C:\Temp\TON20110919113920.CIA and _directory is the “C:\Temp”. When I run the code through the debugger, if the value of currentFile is either TON20110919113920.AB or C:\Temp\TON20110919113920.IA. Notice how the “C” is missing! Why is this happening!? The following is the code snippet:
//>> Snippet Start
private void readDirectoryFiles(str _directory = #InboundFilePath)
{
int idx = 1;
container conDir;
str currentFile;
Filename currentFileName;
str fileType;
FlatFileType flatFileType;
;
conDir = DaxUtility::conListOfFiles(_directory);
while(conLen(conDir) >= idx)
{
currentFile = conPeek(conDir, idx);
currentFileName = strRem(currentFile, _directory);
fileType = subStr(currentFile, strLen(currentFile) - 2, 3); // parse to get the file type
flatFileType = IntegrationFile::getFlatFileTypeFromString(fileType);
//<< Snippet End
Hello MC,
There is no strange behavior of the function strRem and it is working correctly. I’ll explain you more clearly how the function strRem works.
strRem Function: Removes the characters specified in one text string from another text string.
str strRem(str text1, str text2)
Parameter Description
text1 The original text string.
text2 The text string you want to remove the letters from.
Return Value: The remaining content of text1.
If you use the function as:
strRem(“ABCDEFGABCDEFG”,“ACEG”);
Then this function returns the text string “BDFBDF”.
Each individual character included in the string parameter text2 is removed from the string parameter text1 and the remaining content of text1 is returned.
So if the string parameter text2 i.e. _directory has the value “C:\Temp”, then all the 8 individual characters C, :, , T, e, m, p, \ will be removed from the string parameter text1 and the remaining content of text1 will be returned.
Makes much more sense now.
So i guess the question now is, how do I remove a string that is within a string?
Thanks!
I went ahead and figured this out. The code is as follows:
public static str removeString(str mainString, str removeString)
{
;
return strDel(mainString,
strFind(mainString, removeString, 0, strLen(removeString)),
strLen(removeString));
}