my string output
string mystring="my name¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥";
how take ¥¥¥¥¥¥ out of word. im using c#.
i tried this
mystring.trim( '¥' );
but didnt work
im making chat , code
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.net; using system.net.sockets; namespace chat { public partial class form1 : form { socket sck; endpoint eplocal, epremote; public form1() { initializecomponent(); sck = new socket(addressfamily.internetwork, sockettype.dgram, protocoltype.udp); sck.setsocketoption(socketoptionlevel.socket, socketoptionname.reuseaddress, true); textlocalip.text= getlocalip(); textfriendsip.text = getlocalip(); } private string getlocalip() { iphostentry host; host = dns.gethostentry(dns.gethostname()); foreach (ipaddress ip in host.addresslist) { if (ip.addressfamily == addressfamily.internetwork) { return ip.tostring(); } } return "127.0.0.1"; } private void messagecallback(iasyncresult aresult) { try { int size = sck.endreceivefrom(aresult, ref epremote); if (size > 0) { byte[] receiveddata = new byte[1464]; receiveddata = (byte[])aresult.asyncstate; asciiencoding eencoding = new asciiencoding(); string receivedmessage = eencoding.getstring(receiveddata); string c = caesar(receivedmessage, -1); // string recibido se cambia alreves //console.writeline(c.trim( new char[] { '¥' } )); //here doesnt work//////////////////// listmessage.items.add("anonymous: "+c.trim( '¥' )); } byte[] buffer = new byte[1500]; sck.beginreceivefrom(buffer, 0, buffer.length, socketflags.none, ref epremote, new asynccallback(messagecallback), buffer); } catch (exception exp) { messagebox.show(exp.tostring()); } } private void button2_click(object sender, eventargs e) { try { system.text.asciiencoding enc = new system.text.asciiencoding(); string b = caesar(textmessage.text, 1); // sending chipper byte[] msg = new byte[1500]; msg = enc.getbytes(b); sck.send(msg); listmessage.items.add("you: "+textmessage.text); textmessage.clear(); } catch(exception ex) { messagebox.show(ex.tostring()); } } private void button1_click(object sender, eventargs e) { try { //eplocal = new ipendpoint(ipaddress.parse(textlocalip.text, convert.toint32(textlocalport.text)); eplocal = new ipendpoint(ipaddress.parse(textlocalip.text),convert.toint32(textlocalport.text)); sck.bind(eplocal); epremote = new ipendpoint(ipaddress.parse(textfriendsip.text), convert.toint32(textfriendsport.text)); sck.connect(epremote); byte[] buffer = new byte[1500]; sck.beginreceivefrom(buffer, 0, buffer.length, socketflags.none, ref epremote, new asynccallback(messagecallback), buffer); button1.text = "connected!"; button1.enabled = false; button2.enabled = true; textmessage.focus(); } catch(exception ex) { messagebox.show(ex.tostring()); } } static string caesar(string value, int shift) { char[] buffer = value.tochararray(); (int = 0; < buffer.length; i++) { // letter. char letter = buffer[i]; // add shift all. letter = (char)(letter + shift); // subtract 26 on overflow. // add 26 on underflow. if (letter > 'z') { letter = (char)(letter - 26); } else if (letter < 'a') { letter = (char)(letter + 26); } // store. buffer[i] = letter; } return new string(buffer); } }
}
the error marked it, , out put coming out name¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥ want separate it
if expect variable have new value, need make sure assign result it:
mystring = mystring.trim( '¥' );