12-14-2006 09:38 AM
12-14-2006 02:32 PM
The CVI Programmer's Toolbox has a function to remove leading and trailing spaces: RemoveSurroundingWhiteSpace.
To do your Mid function, you can use the ANSI C strncpy function or the Toolbox StringCopyMax function. You do pointer addition to select the starting point
e.g.
char *myString = "0123456789";
char mySubStr[80];
int subStrStart = 2;
int subStrLen = 3;
if (subStrStart > strlen(myString))
mySubStr[0] = '\0';
else
{
strncpy(mySubStr, myString + subStrStart, subStrLen);
mySubStr[subStrLen] = '\0';
}
You can also take a look at using while loops instead of for loops for some applications like your Cut_Right_Space function.
Instead of instead of using for(), if(), and break to find the last non-blank character, use a while loop.
i=strlen(s);
if (i>0)
{
// do-nothing while loop finds the last non-blank character
while (s[--i] == ' ' && i>0);
// terminate the string after the while loop is done
s[i+1]='\0';
}