Note that there are some explanatory texts on larger screens.

plurals
  1. POStrings not being replaced during loop
    text
    copied!<p>I am doing a message loop for a <em>skype bot</em>, 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. </p> <p>Code: </p> <pre><code>if(listView2.SelectedItems.Count&lt;=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); } } </code></pre> <p>If I select three people, named Jim, Tim and Derp, then the first person on the selected list is Jim. If I used <code>%name%</code>, 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 <code>%name%</code> to their names. </p> <hr> <p><strong>Edit:</strong> </p> <p>I know putting <code>value</code>, <code>body</code> 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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload