- Home /
Decode message from internet
Hi, Im making an app where users can send each other messages sent through specific templates and themes. I am having them sent as numbers and letters representative of the theme and message. For example, if the user choses theme a, and the message is "hey", then the thing sent and received by the phone would be: a_hey How can I have the phone understand "a_hey" and put it into variables such as: var theme = a, and text = "hey" Thanks
Answer by YoungDeveloper · Dec 15, 2013 at 01:29 AM
If you want to write that "a" in string itself, then the only way to later "decode" it, is to process that string by single char, and only then post it.
Instead of using just "a" or "b" as first special characters, I suggest using something more readable and rarer, it will save up couple if checks and some code launching on decoding. Lets assume our first special symbol is % and second is the number of template that must be used. For example %2Hey
string messageThatMustBeDecoded = "%1Hey there, how are you doing?"
int templateNumberToUse;
string cleanMessage = "";
void ProcessString(messageThatMustBeDecoded){
for(int i = 0; i < messageThatMustBeDecoded.Length; i++) //Loops through number, which are in the string array element size
if(messageThatMustBeDecoded[i] == '%'){//special symbol found
if(i < messageThatMustBeDecoded.Length-1){ //if its not the end of the string
templateNumberToUse = int.Parse(messageThatMustBeDecoded[i+1]); //parse next element after % (that is number) to int
//So now you pretty much know the template number/index, all we need now is the clean string itself!
i += 2; //We move i where text starts
for(int a = i; a < messageThatMustBeDecoded.Length; a++){ //we go through all remaining text
cleanMessage += messageThatMustBeDecoded[a];
}
return; //function ends!
}
}
}
}
Now "templateNumberToUse" contains the number for template
But "cleanMessage" contains "Hey there, how are you doing?"
The solution will be different for you, because i cant know what exactly you want, but this is very similar and will get you the idea!
Your answer
Follow this Question
Related Questions
global chat 0 Answers
Screenshot PNG to GUITexture (NONE Texture) 0 Answers
Remove .dll 1 Answer
WWWForm.Addfield not able to post data to server 1 Answer
www.text + php + c# issue 2 Answers