Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert C++ function to C#

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hello I have this function to convert to C#. I never worked with C++ so some operators seem confusing. Can someone help me with conversion to C#. Among other things,
how is this possible:
digits[digitIndex] + 'A' - 10;
digits is a int array, how can we add a char and subtract an int from it????

string encodeURLfield(string URLfield)
{
string encodedField = "";
const char *URLfieldC_str = URLfield.c_str();
int URLfieldLength = URLfield.length();
int URLfieldIndex;
int digits[2];
int digitIndex;
char currentChar;
char digitChars[3];

for (URLfieldIndex = 0; URLfieldIndex < URLfieldLength;
++URLfieldIndex)
{
if ((currentChar = *(URLfieldC_str + URLfieldIndex)) == ' ')
encodedField += '+';
else if ((currentChar >= 'A' && currentChar <= 'Z') ||
(currentChar >= 'a' && currentChar <= 'z') ||
(currentChar >= '0' && currentChar <= '9'))
encodedField += currentChar;
else
{
digits[0] = currentChar >> 4;
digits[1] = currentChar & 0x0F;
digitChars[2] = '\0';

for (digitIndex = 0; digitIndex < 2; ++digitIndex)
{
digitChars[digitIndex] = digits[digitIndex] < 10 ?
digits[digitIndex] + '0' :
digits[digitIndex] + 'A' - 10;
}

encodedField = encodedField + "%" + digitChars;
}
}

return(encodedField);
}


thanks for any help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top