I am doing a message loop for a skype bot, it would means I can advertise/mass message easily. However, after the first name string in the loop get replaced by the name in the class, it will only use that name and not replace the new name on the next loop.
Code:
if(listView2.SelectedItems.Count<=0)
return;
string value="Hi %name%!";
string body="";
if(Program.InputBox("New Message", "Body of the message:", ref value)==DialogResult.OK) {
body=value;
}
foreach(ListViewItem i in listView2.SelectedItems) {
String rawID=i.SubItems[7].ToString();
String[] splitID=rawID.Split('}');
String[] ID=splitID[0].Split(new char[] { '{' });
body=body.Replace("%handle%", SkypeUser.Users[Convert.ToInt32(ID[1])].Handle);
body=body.Replace("%name%", SkypeUser.Users[Convert.ToInt32(ID[1])].Name);
body=body.Replace("%status%", SkypeUser.Users[Convert.ToInt32(ID[1])].Status);
body=body.Replace("%country%", SkypeUser.Users[Convert.ToInt32(ID[1])].Country);
body=body.Replace("%mood%", SkypeUser.Users[Convert.ToInt32(ID[1])].Mood);
body=body.Replace("%about%", SkypeUser.Users[Convert.ToInt32(ID[1])].About);
if(!(body==String.Empty)) {
skype.SendMessage(SkypeUser.Users[Convert.ToInt32(ID[1])].Handle, body);
}
}
If I select three people, named Jim, Tim and Derp, then the first person on the selected list is Jim. If I used %name%, it will be correctly replaced to "Jim" in the message to Jim, but the messages to Tim and Derp will also have "Jim", instead of the string replacing %name% to their names.
Edit:
I know putting value, body and if-statements inside the loop; but I want that requiring to input message would be only once. That's the whole point of the mass message.