How to determine remaining escape charecters ?

How to determine remaining escape charecters ? SearchSearch
Author Message
Sajid Ahmed
New member
Username: Sajid

Post Number: 4
Registered: 10-2008
Posted on Thursday, October 09, 2008 - 12:25 pm:   

Hi Friends,

how about other escape characters? such as “?”, “&”, “:” and “=”
here is how i am doing......

private String formatMessageAndPhone(String downloadUrl) {
// TODO Auto-generated method stub

String result="";
final StringCharacterIterator iterator = new StringCharacterIterator(downloadUrl);
char character = iterator.current();
while (character != CharacterIterator.DONE ){
if (character == '"') {
result+="%22";
}
else if (character == '<') {
result+="%3C";
}
else if (character == ' ') {
result+="+";
}
else if (character == '>') {
result+="%3E";
}
else if (character == '&') {
result+="%26";
}
else if (character == '+') {
result+="%2B";
}
else if (character == '#') {
result+="%23";
}
else if (character == '%') {
result+="%25";
}
else if (character == '*') {
result+="%2A";
}
else if (character == '!') {
result+="%21";
}
else if (character == ',') {
result+="%2C";
}
else if (character == '\'') {
result+="%27";
}
else if (character == '\') {
result+="%5C";
}
else if (character == '=') {
result+="%3D";
}
else if (character == '€') {
result+="%E2%82%AC";
}
else {
//the char is not a special one
//add it to the result as is
result+=character;
}
character = iterator.next();
}
return result;

}


http://127.0.0.1:8800/?PhoneNumber=%2B447778001210&Text=abc+def+ghi

Substitute the text of the SMS message in the “Text” parameter. Note that due to URL escaping restrictions, space characters should be replaced with “+” characters. Also, certain special characters, such as “?”, “&”, “:” and “=” need to be replaced with an escape character. The gateway expects characters to be encoded in UTF-8 (Unicode-based) format, therefore some characters, including the Euro (€) may require multiple escaped characters. (Note: The Web Menu Interface automatically performs this escaping.) The following table shows common characters that must be escaped

please help me to convert all escape char to correct format..

Thanks & Regards,

Sajid
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 134
Registered: 08-2008
Posted on Thursday, October 09, 2008 - 01:57 pm:   

Hi Sajid,

It looks like you're working in JavaScript, right?

Why not use the encodeURIComponent function instead? That's what it's purpose is ... to perform URL escaping so that parameters can be properly encoded for a URL.

Here's an example where I'll build the URL by using encodeURIComponent to make sure to properly encode several URL parameters:

var NowSMSServerAddress = "http://127.0.0.1:8800";
var NowSMSUserName = "test";
var NowSMSPassword = "test";
var recipientPhoneNumber = "+447777777777";
var messageText = "This is the text of the message ?&:=";

strRequest = NowSMSServerAddress + "/?PhoneNumber=" + encodeURIComponent(recipientPhoneNumber) + "&User=" + encodeURIComponent(NowSMSUserName) + "&password=" + encodeURIComponent(NowSMSPassword) + "&text=" + encodeURIComponent(messageText);


--
Des
NowSMS Support