If I have a string variable, is there a way to get the Replace method to
work on *its* contents, without having to dimenstion a second variable?
Something like:
Dim MyTest as String = "<hello/>"
MyTest.Replace("<", "<")
MyTest.Replace(">", ">")
'MyTest now equals "<hello>"
This code doesn't work the way that I would expect. Can someone shed some
light on this?
Thanks,
Craig 4 1133
"Craig Buchanan" <so*****@microsoft.com> schrieb If I have a string variable, is there a way to get the Replace method to work on *its* contents, without having to dimenstion a second variable? Something like:
Dim MyTest as String = "<hello/>" MyTest.Replace("<", "<") MyTest.Replace(">", ">")
'MyTest now equals "<hello>"
This code doesn't work the way that I would expect. Can someone shed some light on this?
Replace is a function. It returns a *new* string because the string content
can *not* be changed.
mytest = MyTest.Replace("<", "<")
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Craig Buchanan" <so*****@microsoft.com> wrote in message
news:ec*************@tk2msftngp13.phx.gbl... If I have a string variable, is there a way to get the Replace method to work on *its* contents, without having to dimenstion a second variable? Something like:
Dim MyTest as String = "<hello/>" MyTest.Replace("<", "<") MyTest.Replace(">", ">")
'MyTest now equals "<hello>"
This code doesn't work the way that I would expect. Can someone shed some light on this?
Thanks,
Craig
If you need to modify existing contents, you need to use the
System.Text.StringBuilder class instead of the String class. StringBuilder
objects are mutable. String objects are immutable.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Hi Peter, If you need to modify existing contents, you need to use the System.Text.StringBuilder class instead of the String class. StringBuilder objects are mutable. String objects are immutable.
To my suprise as well has that no effect on the replace, the string replace
is slighly faster, we did a test in this newsgroup, here the final link to
that thread. http://tinyurl.com/3bogd
Cor
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl... Hi Peter,
If you need to modify existing contents, you need to use the System.Text.StringBuilder class instead of the String class.
StringBuilder objects are mutable. String objects are immutable. To my suprise as well has that no effect on the replace, the string
replace is slighly faster, we did a test in this newsgroup, here the final link to that thread.
http://tinyurl.com/3bogd
Cor
I was referring to the general issue of mutability. Not in particular to the
Replace method, or to any performance concerns. The parameter lists for the
Replace methods for the two classes explains the behavior. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Roose |
last post by:
How can I do a "".replace operation which tells me if anything was
actually replaced?
Right now I am doing something like:
if searchTerm in text:
text = text.replace( searchTerm, 'other' )
...
|
by: higabe |
last post by:
Three questions
1)
I have a string function that works perfectly but according to W3C.org
web site is syntactically flawed because it contains the characters </
in sequence. So how am I...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: Dan Schumm |
last post by:
I'm relatively new to regular expressions and was looking for some help on a
problem that I need to solve. Basically, given an HTML string, I need to
highlight certain words within the text of the...
|
by: Jeff S |
last post by:
In a VB.NET code behind module, I build a string for a link that points to a
JavaScript function. The two lines of code below show what is relevant.
PopupLink = "javascript:PopUpWindow(" &...
|
by: Peter Row |
last post by:
Hi,
I know this has been asked before, but reading the threads it is still not
entirely clear.
Deciding which .Replace( ) to use when.
Typically if I create a string in a loop I always use a...
|
by: djc |
last post by:
I need to prepare a large text database field to display in an asp.net
repeater control. Currently I am replacing all chr(13)'s with a "<br/>" and
it works fine. However, now I also want to be able...
|
by: billpaterson2006 |
last post by:
I've been working on some code to search for specific textstrings and
act upon them insome way. I've got the conversion sorted however there
is 1 problem remaining.
I am trying to work out how...
|
by: MLH |
last post by:
Back in mid-2003, lucason posted a question about removing
punctuation chars from a string. Suggested code was posted
using Replace function. Could the FN below be easily modified
for use with A97...
|
by: TC |
last post by:
Hey All,
I have strings in currency. For example: "$1.29"
What is the best way to convert them to decimal formatted like: "1.29"
Thanks,
TC
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |