Dear all,
I need to replace in a long string all chr(10) to chr(10)chr(13) if 13 is
not behind 10.
dim str as string=....
If str.Chars(i) = vbLf And str.Chars(i + 1) <> vbCr Then
str.Insert(i, vbCr)
i = i + 1
End If
But if set a breakpoint on insert and look on str before and after insert I
can see, that vbCr is just not inserted!!! ascii(str.Chars(i) ) and
str.Chars(i+/-1) are not 13!!!
What is wrong??
Thanks,
Boni 4 976
The answer is that strings are immutable, meaning they cannot change.
The insert method returns a new strings with your changes, therefore
you need to assign it back to your string variable:
str = str.Insert(i,vbCr)
Or noooo. Soo simple. I might need some sleep !
Thanks Chris
"Chris Dunaway" <du******@gmail.com> schrieb im Newsbeitrag
news:11**********************@f14g2000cwb.googlegr oups.com... The answer is that strings are immutable, meaning they cannot change. The insert method returns a new strings with your changes, therefore you need to assign it back to your string variable:
str = str.Insert(i,vbCr)
Hi,
String.Insert doesn't change the original string (as well as other
String methods), but generates a new
one instead.
So,
1. Use str = str.Insert(i,vbCr) - or -
2. Use StringBuilder for that.
BTW, have you considered using RegEx for this kind of job? It's pretty
simple:
str = System.Text.RegularExpressions.Regex.Replace(str, "\x0a(?!\x0d)",
Chr(10) & Chr(13))
Roman
Hi Dragon,
I was thinking about regexes, but my feeling was to avoid regexes for simple
things because of performance reasons. But as I see the building of temp
string objects seems to take time too. So I switch to regex. I don't think
that I will mention timing difference.
Thank you for an advice,
Boni
"Dragon" <no@spam.please> schrieb im Newsbeitrag
news:eF**************@TK2MSFTNGP14.phx.gbl... Hi,
String.Insert doesn't change the original string (as well as other String methods), but generates a new one instead.
So, 1. Use str = str.Insert(i,vbCr) - or - 2. Use StringBuilder for that.
BTW, have you considered using RegEx for this kind of job? It's pretty simple: str = System.Text.RegularExpressions.Regex.Replace(str, "\x0a(?!\x0d)", Chr(10) & Chr(13))
Roman This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: NanQuan |
last post by:
I'm hoping someone can help me solve this error since I am at a total
loss here. Usually I don't bother posting on any forums or groups on
the internet and prefer to solve stuff myself but this is...
|
by: Kaneda |
last post by:
Hello everyone!
I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.
I have a ComboBox I need to fill with the...
|
by: Kaneda |
last post by:
Hello everyone!
I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.
I have a ComboBox I need to fill with the...
|
by: Chris Mantoulidis |
last post by:
PROBLEM: I'm having some weird problems with string::find() (in
ParamGenerate()), but since I'm not sure if that is the source of all
bad output in my program, I'm posting least code that's...
|
by: Ot |
last post by:
I have two different solutions that use xml serialization to create xml
from a given class.
The class is defined identically in both solutions. I copied the code for
both the class and the code...
|
by: Scott Reynolds |
last post by:
I am having a problem exposing a class inherited from the collection base
class as a webservice. If I expose the collection on a web page all works
well and I am very happy.
However when I try and...
|
by: Nak |
last post by:
Hi there,
It's probably me being weird more than the function but I'm having
problems with it doing as it should.
I have a C++ application with 2 resources of custom types,
RT_INIFILE @...
|
by: Jim Strathmeyer |
last post by:
So I'm having some weird problems with file output. If I try to boil
this problem down to a small, simple program to just show what problems
I'm having, I can't get the same problematic behavior. I...
|
by: P Pulkkinen |
last post by:
Dear all,
sorry, i know this code is far little too long to debug here, but there is
really annoying logical error. If someone debugs this, I really offer warm
virtual handshake.
What this...
|
by: drjack |
last post by:
Recently I developed a website using asp.net and SQL Express. The database file is uploaded into App_Data folder. The website is using two membership providers, one is SqlMemership provider with...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |