473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

weird string problem

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
Nov 21 '05 #1
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)

Nov 21 '05 #2
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)

Nov 21 '05 #3
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

Nov 21 '05 #4
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

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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...
1
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...
0
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...
1
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...
1
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...
2
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...
14
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 @...
5
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.