developer155
Programmer
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
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