LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

need to hex encode string like escape() function

In java there is the escape() function which replaces all characters other
than letters and numbers with %xx notation. Is there something analogous in
CVI-land?
0 Kudos
Message 1 of 3
(3,263 Views)
Hello Willie,
In LabWindows/CVI, the string manipulation functions can be found in either the ANSI C Library or the CVI Formatting and IO Library. I do not recall hearing of such a function in CVI, and after double-checking it does not look as though CVI provides a function that does this. You will either need to write your own escape() routine, obtain one from another vendor, or somehow wrap and link to the escape() Java function. Good Luck!

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 3
(3,263 Views)
I am still not able to get this to work. Here is the function that I wrote to simulate the escape() function. There is a page on the Netscape site that I am testing it against- developer.netscape.com/viewsource/husted_mailto/mailto.html

They encode "<$"%123" into %22%3C%24%22%25123%22. I have written URLencode below to simulate this. I can't even compile when I set pszString="<$/"%123" because I get a missing " error on the last quote. BTW, they set spaces to equal %20, not +.


char szEncoded[200];
void URLEncode(char *pszString)
{
char szChar[3];
int iChar;

memset(szEncoded,0,sizeof(szEncoded));
j=0;
for (i=0;i {
// don't touch alphanumeric chars
if (((pszString[i]>=48)&&(pszString[i]<=57))||
((pszString[i]>=65
)&&(pszString[i]<=90))||
((pszString[i]>=97)&&(pszString[i]<=122)))
{
szEncoded[j]=pszString[i];
j++;
continue;
}
if (pszString[i]==32) //' replace space with "+"
{
szEncoded[j]='+';
j++;
continue;
}

//Else
// ' replace punctuation chars with "%hex"
szEncoded[j]='%';
j++;
iChar=pszString[i];
sprintf(szChar,"%x",iChar);
strncat(szEncoded,szChar,2);
j=j+2;
}
}
0 Kudos
Message 3 of 3
(3,263 Views)