Multiple .replace() in asp.net/vb.net

N

Neo Geshel

Greetings

I am using VB in my ASP.NET project that uses an admin web site to
populate a database that provides content for a front end web site. I am
looking for a way to use replace() to replace multiple entries of an
object within a string. That is, if a user hit [enter] twice to create
one new line, but [enter] just once to create another, I want both types
([vbcrlf vbcrlf] & [vbcrlf}) replaced by </p><p>.

The reason is this: I don't want to strip out multiple vbcrlf's at the
admin site/database, because the users are used to hitting [enter] twice
to create a new line (by creating a blank line between paragraphs).
However, when the content is displayed on the front end site, I need to
replace *any number* of sequential vbcrlf's (from just a single one, to
multiple ones of any number) with a single </p>vbcrlf[tab character]<p>
(the data will be dumped inside a single paragraph: <p>[data]</p>, so
this replacement of vbcrlf will break up the data into multiple paragraphs).

I am also curious as to how to string multiple replace()'s together.
That is, I want to convert regular quotes to curly quotes. I want to
replace one kind of single quote "text -> “text and then within the same
string also replace another kind of single quote text" -> textâ€. I am
sure that the replace() was built to have multiple expressions within
the bracket, but I can't seem to find any info on that.

And finally, any info on how to explicitly set certain special
characters, like tabs and spaces (much like how vbcrlf creates a return)
would be appreciated.

TIA
...Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
M

Michael Earls

You should look into learning about the RegEx class. It's daunting at
first, but it will allow you to create replacements that you need easily.
--
Michael Earls
The Cerebral Kitchen
http://www.cerkit.com/


Greetings

I am using VB in my ASP.NET project that uses an admin web site to
populate a database that provides content for a front end web site. I am
looking for a way to use replace() to replace multiple entries of an
object within a string. That is, if a user hit [enter] twice to create
one new line, but [enter] just once to create another, I want both types
([vbcrlf vbcrlf] & [vbcrlf}) replaced by </p><p>.

The reason is this: I don't want to strip out multiple vbcrlf's at the
admin site/database, because the users are used to hitting [enter] twice
to create a new line (by creating a blank line between paragraphs).
However, when the content is displayed on the front end site, I need to
replace *any number* of sequential vbcrlf's (from just a single one, to
multiple ones of any number) with a single </p>vbcrlf[tab character]<p>
(the data will be dumped inside a single paragraph: <p>[data]</p>, so
this replacement of vbcrlf will break up the data into multiple paragraphs).

I am also curious as to how to string multiple replace()'s together.
That is, I want to convert regular quotes to curly quotes. I want to
replace one kind of single quote "text -> "text and then within the same
string also replace another kind of single quote text" -> text". I am
sure that the replace() was built to have multiple expressions within
the bracket, but I can't seem to find any info on that.

And finally, any info on how to explicitly set certain special
characters, like tabs and spaces (much like how vbcrlf creates a return)
would be appreciated.

TIA
....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
R

Rick Mogstad

replace all double VBCRLFs with single ones repeatedly until there are no
double VBCRLFs left, then do your replace.

Dim x As String

Do While x.IndexOf(System.Environment.NewLine & System.Environment.NewLine)

x = Replace(x, System.Environment.NewLine & System.Environment.NewLine,
System.Environment.NewLine)

Loop

x = Replace(x, System.Environment.NewLine, "</p><p>")


Greetings

I am using VB in my ASP.NET project that uses an admin web site to
populate a database that provides content for a front end web site. I am
looking for a way to use replace() to replace multiple entries of an
object within a string. That is, if a user hit [enter] twice to create
one new line, but [enter] just once to create another, I want both types
([vbcrlf vbcrlf] & [vbcrlf}) replaced by </p><p>.

The reason is this: I don't want to strip out multiple vbcrlf's at the
admin site/database, because the users are used to hitting [enter] twice
to create a new line (by creating a blank line between paragraphs).
However, when the content is displayed on the front end site, I need to
replace *any number* of sequential vbcrlf's (from just a single one, to
multiple ones of any number) with a single </p>vbcrlf[tab character]<p>
(the data will be dumped inside a single paragraph: <p>[data]</p>, so
this replacement of vbcrlf will break up the data into multiple paragraphs).

I am also curious as to how to string multiple replace()'s together.
That is, I want to convert regular quotes to curly quotes. I want to
replace one kind of single quote "text -> "text and then within the same
string also replace another kind of single quote text" -> text". I am
sure that the replace() was built to have multiple expressions within
the bracket, but I can't seem to find any info on that.

And finally, any info on how to explicitly set certain special
characters, like tabs and spaces (much like how vbcrlf creates a return)
would be appreciated.

TIA
....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
H

Hans Kesting

Neo said:
Greetings


I am also curious as to how to string multiple replace()'s together.
That is, I want to convert regular quotes to curly quotes. I want to
replace one kind of single quote "text -> "text and then within the
same string also replace another kind of single quote text" -> text".
I am sure that the replace() was built to have multiple expressions within
the bracket, but I can't seem to find any info on that.


TIA
...Geshel

You can't write multiple replacements with a single bracket-pair,
but you can use something like
myString = myString.Replace(..).Replace(...).Replace(...)

Maybe you can replace "<space><quote>" with "<space><open curly quote>"
and so on.

Hans Kesting
 
G

Guest

Use Regex to replace. You can set up Regex with a pattern that replaces one,
or more, instances of \r\n with </p><p>. It would be far more costly to have
it loop until all \r\n were replaced.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,101
Latest member
MarcusSkea
Top