435,389 Members | 2,070 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

String.Replace dont work?

 P: n/a dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #1
9 Replies

 P: n/a I think you must do pp = pp.Replace("{", Nothing) pp = pp.Replace("}", Nothing) pp = pp.Replace("X=", Nothing) pp = pp.Replace("Y=", Nothing) function replace (string) as string lobrys "Crirus" a écrit dans le message de news:ez*************@tk2msftngp13.phx.gbl... dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #2

 P: n/a Crirus, I Thought Dim Crirus as String = pp.Replace(.................... (String member) or just Dim Crirus as String = Replace( (String Function) I hope this helps a little bit? Cor Nov 20 '05 #3

 P: n/a Sorry, solved...I have to assign it back to pp "Crirus" wrote in message news:ez*************@tk2msftngp13.phx.gbl... dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #4

 P: n/a * "Cor" scripsit: Dim Crirus as String = pp.Replace(.................... (String member) or just Dim Crirus as String = Replace( (String Function) Member of 'Microsoft.VisualBasic.Strings'. ;-) -- Herfried K. Wagner MVP · VB Classic, VB.NET Improve your quoting style: Nov 20 '05 #5

 P: n/a Crirus, In addition to your & the other comments about need to assign the result back to a variable. With four replaces in a row as you have, I would consider using StringBuilder.Replace instead of String.Replace. Something like: Imports System.Text dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" Dim sb As New StringBuilder(pp) sb.Replace("{", Nothing) sb.Replace("}", Nothing) sb.Replace("X=", Nothing) sb.Replace("Y=", Nothing) pp = sb.ToString() Especially if I was using string concatenation to build pp in the first place. As I would use StringBuild.Append to build the string, then use the above Replace statements to clean it. Dim sb As New StringBuilder(pp) sb.Append(pt1.ToString()) sb.Append(pt2.ToString()) sb.Append(pt3.ToString()) ... sb.Replace("{", Nothing) ... Hope this helps Jay "Crirus" wrote in message news:ez*************@tk2msftngp13.phx.gbl... dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #6

 P: n/a Is faster that way? Any other advantages? "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... Crirus, In addition to your & the other comments about need to assign the result back to a variable. With four replaces in a row as you have, I would consider using StringBuilder.Replace instead of String.Replace. Something like: Imports System.Text dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" Dim sb As New StringBuilder(pp) sb.Replace("{", Nothing) sb.Replace("}", Nothing) sb.Replace("X=", Nothing) sb.Replace("Y=", Nothing) pp = sb.ToString() Especially if I was using string concatenation to build pp in the first place. As I would use StringBuild.Append to build the string, then use the above Replace statements to clean it. Dim sb As New StringBuilder(pp) sb.Append(pt1.ToString()) sb.Append(pt2.ToString()) sb.Append(pt3.ToString()) ... sb.Replace("{", Nothing) ... Hope this helps Jay "Crirus" wrote in message news:ez*************@tk2msftngp13.phx.gbl... dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #7

 P: n/a Hi Crirus, To give my opinion to add to the message from Jay B. because I fully agree with him. I don't think there is a big advantages in this example. But the advantage is to get used to the Stringbuilder because the building of strings is always been in every computer language a time spending part and has never been really good implemented. Now we have a better way, so lets use it than we take it the next time automaticly. I was glad with this message from Jay B. I will try to use it next time when I give an example. Just a thought. Cor Nov 20 '05 #8

 P: n/a Crirus, It really depends on how you are building the string. For four simple replacements. I would expect it to be a wash (the same time). However if you have a series of string concatenations before the replacements, then yes I would expect the StringBuilder to be faster. The other major advantage, each time you call string.Replace you are creating a new temporary string object, if you do 4 replacements you will have 4 temporary string objects. With the StringBuilder you will have 1 temporary stringbuilder object, so you are saving 3 objects that the GC needs to worry about. Would I worry about just the 3 objects, probably not. However if I decided I needed 10 replacements or 20 replacements I think you will find that the StringBuilder quickly becomes the better deal... Hope this helps Jay "Crirus" wrote in message news:eZ**************@TK2MSFTNGP11.phx.gbl... Is faster that way? Any other advantages? "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... Crirus, In addition to your & the other comments about need to assign the result back to a variable. With four replaces in a row as you have, I would consider using StringBuilder.Replace instead of String.Replace. Something like: Imports System.Text dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" Dim sb As New StringBuilder(pp) sb.Replace("{", Nothing) sb.Replace("}", Nothing) sb.Replace("X=", Nothing) sb.Replace("Y=", Nothing) pp = sb.ToString() Especially if I was using string concatenation to build pp in the first place. As I would use StringBuild.Append to build the string, then use the above Replace statements to clean it. Dim sb As New StringBuilder(pp) sb.Append(pt1.ToString()) sb.Append(pt2.ToString()) sb.Append(pt3.ToString()) ... sb.Replace("{", Nothing) ... Hope this helps Jay "Crirus" wrote in message news:ez*************@tk2msftngp13.phx.gbl... dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, Y=100}{X=200, Y=122.3858}{X=200, Y=150}" pp.Replace("{", Nothing) pp.Replace("}", Nothing) pp.Replace("X=", Nothing) pp.Replace("Y=", Nothing) after this, pp is exactly the same as before??!! Crirus Nov 20 '05 #9

 P: n/a Good to see this for future needs...thanks "Jay B. Harlow [MVP - Outlook]" wrote in message news:eW**************@tk2msftngp13.phx.gbl... Crirus, It really depends on how you are building the string. For four simple replacements. I would expect it to be a wash (the same time). However if you have a series of string concatenations before the replacements, then yes I would expect the StringBuilder to be faster. The other major advantage, each time you call string.Replace you are creating a new temporary string object, if you do 4 replacements you will have 4 temporary string objects. With the StringBuilder you will have 1 temporary stringbuilder object, so you are saving 3 objects that the GC needs to worry about. Would I worry about just the 3 objects, probably not. However if I decided I needed 10 replacements or 20 replacements I think you will find that the StringBuilder quickly becomes the better deal... Hope this helps Jay "Crirus" wrote in message news:eZ**************@TK2MSFTNGP11.phx.gbl... Is faster that way? Any other advantages? "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... Crirus, In addition to your & the other comments about need to assign the result back to a variable. With four replaces in a row as you have, I would consider using StringBuilder.Replace instead of String.Replace. Something like: Imports System.Text > dim pp as string > pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, > Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, > Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, > Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, > Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, > Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, > Y=100}{X=200, Y=122.3858}{X=200, Y=150}" Dim sb As New StringBuilder(pp) sb.Replace("{", Nothing) sb.Replace("}", Nothing) sb.Replace("X=", Nothing) sb.Replace("Y=", Nothing) pp = sb.ToString() Especially if I was using string concatenation to build pp in the first place. As I would use StringBuild.Append to build the string, then use the above Replace statements to clean it. Dim sb As New StringBuilder(pp) sb.Append(pt1.ToString()) sb.Append(pt2.ToString()) sb.Append(pt3.ToString()) ... sb.Replace("{", Nothing) ... Hope this helps Jay "Crirus" wrote in message news:ez*************@tk2msftngp13.phx.gbl... > dim pp as string > pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, > Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, > Y=200.7715}{X=200.7715, Y=156}{X=256, Y=156}{X=311.2285, Y=156}{X=356, > Y=200.7715}{X=356, Y=256}{X=200, Y=150}{X=200, Y=177.6142}{X=177.6142, > Y=200}{X=150, Y=200}{X=122.3858, Y=200}{X=100, Y=177.6142}{X=100, > Y=150}{X=100, Y=122.3858}{X=122.3858, Y=100}{X=150, Y=100}{X=177.6142, > Y=100}{X=200, Y=122.3858}{X=200, Y=150}" > > pp.Replace("{", Nothing) > pp.Replace("}", Nothing) > pp.Replace("X=", Nothing) > pp.Replace("Y=", Nothing) > > after this, pp is exactly the same as before??!! > > Crirus > > > Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion. 