Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to Replace vbcrlf outside html tags in memo field of access database

Reply
 
Old 04-30-2009   #1 (permalink)
S N


 
 

How to Replace vbcrlf outside html tags in memo field of access database

I am storing text formatted as HTML table alongwith text in many paragraphs
in MS Access Memo field.
However, when I try to print the text as formatted paragraphs using the
following command:

fldtext=recordSet("fldMemo")
fldtext1=Replace(fldtext,vbcrlf,"<br />")

response.write(fldtext1)


The paragraphs are formatted alright and the table also appears alright
separately. But there are many blank lines inserted automatically before the
table which destroy the whole formatting.
There is no problem in case there is no table stored alongwith the paragraph
text and no blank unnecessary lines appear.

If I comment out the replace statement, i dont get any <BR> tags which is
also not desirable.
I want that <BR> tags should be inserted only with paragraph marks and not
with every tag related to table as is happening in the code indicated.
Please help how to ensure that the blank lines are not appearing in the
text.

I feel the solution lies in being able to modify text outside any html tag
(like table tag) using regular expressions in vbscript.

Can someone give the code on how to modify the text outside any closed html
tag like <table> using vbscript regular expressions. This would help in
modifying the line breaks outside the table tag and replacing them by <BR>
tags. This would also ensure that the <BR> tags are not replaced inside the
<table> tags which would actually create problems as present.

The view source is giving me the following text:
-----------------------------------

This is the starting text <BR /><table cellspacing="0" cellpadding="0"
rules="all" width="70%" align="center" border="1"><BR /> <tbody><BR />
<tr><BR /> <td width="50">S No</td><BR /> <td
width="185">Name</td><BR /> <td width="261">Unit</td><BR />
</tr><BR /> <tr><BR /> <td>1</td><BR />
<td>ABC</td><BR /> <td>DEF</td><BR /> </tr><BR />
<tr><BR /> <td>2</td><BR /> <td>GHI</td><BR />
<td>JKL</td><BR /> </tr><BR /> <tr><BR />
<td>3</td><BR /> <td>MNO</td><BR /> <td>PQ</td><BR />
</tr><BR /> <tr><BR /> <td>4</td><BR />
<td>RST</td><BR /> <td>UV</td><BR /> </tr><BR />
<tr><BR /> </tbody><BR /></table><BR />

________________________________________________________

The following is the text as exactly present in the memo field in Access
database:
-----------------------------------

This is the starting text
<table cellspacing="0" cellpadding="0" rules="all" width="70%"
align="center" border="1">
<tbody>
<tr>
<td width="50">S No</td>
<td width="185">Name</td>
<td width="261">Unit</td>
</tr>
<tr>
<td>1</td>
<td>ABC</td>
<td>DEF</td>
</tr>
<tr>
<td>2</td>
<td>GHI</td>
<td>JKL</td>
</tr>
<tr>
<td>3</td>
<td>MNO</td>
<td>PQ</td>
</tr>
<tr>
<td>4</td>
<td>RST</td>
<td>UV</td>
</tr>
</tbody>
</table>
______________________________________________

Please advise as to how to ensure that the line breaks in paragraphs get
converted into <BR /> without getting multiple <BR /> tags inserted due to
table items.

Please help

uandme72


My System SpecsSystem Spec
Old 04-30-2009   #2 (permalink)
S N


 
 

Re: How to Replace vbcrlf outside html tags in memo field of access database

Few issues with your solution:
1. File system object not permitted by my ISP. HEnce cannot be used in the
code.
2. Actually I want to replace all VBCRLF which appear in paragraph and not
those VBCRLF which appear as a line change character as in the structure of
any html table. The following is the sample text where I dont need VBCRLF
replacement (after <tbody> or after <tr> or after</td> etc).


<tbody>
<tr>
<td width="50">S No</td>
<td width="185">Name</td>
<td width="261">Unit</td>

Whereas I need VBCRLF replacement in the following text:
My name is ABC DEF.
His name is FGHU HEEN.

VBCRLF after the string DEF. should be replaced by <BR />

Kindly advise on how to replace vbcrlf considering the above problems.

uandme72



"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:49f95baa$0$32680$9b4e6d93@xxxxxx-online.net...
Quote:

>S N schrieb:
Quote:

>> I am storing text formatted as HTML table alongwith text in many
>> paragraphs
>> in MS Access Memo field.
>> However, when I try to print the text as formatted paragraphs using the
>> following command:
>>
>> fldtext=recordSet("fldMemo")
>> fldtext1=Replace(fldtext,vbcrlf,"<br />")
>>
>> response.write(fldtext1)
>>
>>
>> The paragraphs are formatted alright and the table also appears alright
>> separately. But there are many blank lines inserted automatically before
>> the
>> table which destroy the whole formatting.
>> There is no problem in case there is no table stored alongwith the
>> paragraph
>> text and no blank unnecessary lines appear.
>>
>> If I comment out the replace statement, i dont get any <BR> tags which is
>> also not desirable.
>> I want that <BR> tags should be inserted only with paragraph marks and
>> not
>> with every tag related to table as is happening in the code indicated.
>> Please help how to ensure that the blank lines are not appearing in the
>> text.
>>
>> I feel the solution lies in being able to modify text outside any html
>> tag
>> (like table tag) using regular expressions in vbscript.
>>
>> Can someone give the code on how to modify the text outside any closed
>> html
>> tag like <table> using vbscript regular expressions. This would help in
>> modifying the line breaks outside the table tag and replacing them by
>> <BR>
>> tags. This would also ensure that the <BR> tags are not replaced inside
>> the
>> <table> tags which would actually create problems as present.
>>
>> The view source is giving me the following text:
>> -----------------------------------
>>
>> This is the starting text <BR /><table cellspacing="0" cellpadding="0"
>> rules="all" width="70%" align="center" border="1"><BR /> <tbody><BR />
>> <tr><BR /> <td width="50">S No</td><BR /> <td
>> width="185">Name</td><BR /> <td width="261">Unit</td><BR />
>> </tr><BR /> <tr><BR /> <td>1</td><BR />
>> <td>ABC</td><BR /> <td>DEF</td><BR /> </tr><BR />
>> <tr><BR /> <td>2</td><BR /> <td>GHI</td><BR />
>> <td>JKL</td><BR /> </tr><BR /> <tr><BR />
>> <td>3</td><BR /> <td>MNO</td><BR /> <td>PQ</td><BR
>> />
>> </tr><BR /> <tr><BR /> <td>4</td><BR />
>> <td>RST</td><BR /> <td>UV</td><BR /> </tr><BR />
>> <tr><BR /> </tbody><BR /></table><BR />
>>
>> ________________________________________________________
>>
>> The following is the text as exactly present in the memo field in Access
>> database:
>> -----------------------------------
>>
>> This is the starting text
>> <table cellspacing="0" cellpadding="0" rules="all" width="70%"
>> align="center" border="1">
>> <tbody>
>> <tr>
>> <td width="50">S No</td>
>> <td width="185">Name</td>
>> <td width="261">Unit</td>
>> </tr>
>> <tr>
>> <td>1</td>
>> <td>ABC</td>
>> <td>DEF</td>
>> </tr>
>> <tr>
>> <td>2</td>
>> <td>GHI</td>
>> <td>JKL</td>
>> </tr>
>> <tr>
>> <td>3</td>
>> <td>MNO</td>
>> <td>PQ</td>
>> </tr>
>> <tr>
>> <td>4</td>
>> <td>RST</td>
>> <td>UV</td>
>> </tr>
>> </tbody>
>> </table>
>> ______________________________________________
>>
>> Please advise as to how to ensure that the line breaks in paragraphs get
>> converted into <BR /> without getting multiple <BR /> tags inserted due
>> to
>> table items.
>>
>> Please help
>>
>> uandme72
>
> Having problems to link your description "text formatted as HTML
> table alongwith text in many paragraphs" with your sample (no
> paragraphs at all), my code sample tries to solve this task:
>
> Given a string of two parts (separated by </table>), apply
> a replace operation to the second part only.
>
> Code:
>
> Dim sSep : sSep = "</table>" & vbCrLf
> Dim sSearch : sSearch = vbCrLf
> Dim sReplace : sReplace = "<br />" & vbCrLf
>
> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> Dim sFSpec : sFSpec = ".\replCrLfHtmlIn.txt"
> Dim sText : sText = oFS.OpenTextFile( sFSpec ).ReadAll()
> Dim aParts : aParts = Split( sText, sSep )
>
> If 1 = UBound( aParts ) Then
> sText = aParts( 0 ) & sSep _
> & Replace( aParts( 1 ), sSearch, sReplace, 1, -1,
> vbTextCompare )
> WScript.Echo sText
> Else
> WScript.Echo "Bingo!"
> End If
>
> Output:
>
> === replCrLfHtml: replace CrLf in HTML =====================
> This is the starting text (CrLf should not be changed)
> <table cellspacing="0">
> <tbody>
> <tr>
> <td width="50">S No</td>
> <td width="185">Name</td>
> <td width="261">Unit</td>
> </tr>
> </tbody>
> </table>
> This is the first line (paragraph?) of the plain text<br />
> section; CrLf should be changed to <br /> (& CrLf?).<br />
> This is the second line (paragraph?) of the plain text<br />
> section; CrLf should be changed to <br /> (& CrLf?).<br />
>
> === replCrLfHtml: 0 done (00:00:00) ========================

My System SpecsSystem Spec
Old 04-30-2009   #3 (permalink)
Todd Vargo


 
 

Re: How to Replace vbcrlf outside html tags in memo field of access database


"S N" <uandme72@xxxxxx> wrote in message
news:%23voExrUyJHA.140@xxxxxx
Quote:

> I am storing text formatted as HTML table alongwith text in many
paragraphs
Quote:

> in MS Access Memo field.
> However, when I try to print the text as formatted paragraphs using the
> following command:
>
> fldtext=recordSet("fldMemo")
> fldtext1=Replace(fldtext,vbcrlf,"<br />")
Assuming your html has no Chr(8) characters, try this.

fldtext1 = Replace(fldtext, ">" & vbcrlf, Chr(8))
fldtext1 = Replace(fldtext1, vbcrlf, "<br />")
fldtext1 = Replace(fldtext1, Chr(8), ">" & vbcrlf)

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 05-01-2009   #4 (permalink)
ekkehard.horner


 
 

Re: How to Replace vbcrlf outside html tags in memo field of accessdatabase

S N schrieb:
Quote:

> Few issues with your solution:
> 1. File system object not permitted by my ISP. HEnce cannot be used in the
> code.
The FSO is used just for the demo. As I don't have your .mdb, I had to get
some text to work on from somewhere. It's not needed for my proposal: split
the text at the *logical* boundary (closing table tag) to be able to apply
the replace operation on the 'plain text' section only.

The differences to Todd Vargo's solution:

(1) con: two ops (split and replace)instead of just one (replace)
(so perhaps you should use his approach)
(2) pro: no risk of skipping a ">" at the end of a line in the
second part
(depending on your data, this may be a very slim risk)
Quote:

> 2. Actually I want to replace all VBCRLF which appear in paragraph and not
> those VBCRLF which appear as a line change character as in the structure of
> any html table. The following is the sample text where I dont need VBCRLF
> replacement (after <tbody> or after <tr> or after</td> etc).
>
>
> <tbody>
> <tr>
> <td width="50">S No</td>
> <td width="185">Name</td>
> <td width="261">Unit</td>
>
> Whereas I need VBCRLF replacement in the following text:
> My name is ABC DEF.
> His name is FGHU HEEN.
>
> VBCRLF after the string DEF. should be replaced by <BR />
>
While there is certainly room for improvement of specification (lines <>
paragraphs (<p>)) and implementation (no </br > on the last line?), I
still claim that my code does just that.

[...]
Quote:

> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
> news:49f95baa$0$32680$9b4e6d93@xxxxxx-online.net...
Quote:

>> S N schrieb:
Quote:

>>> I am storing text formatted as HTML table alongwith text in many
>>> paragraphs
[...]
Quote:
Quote:
Quote:

>>> I want that <BR> tags should be inserted only with paragraph marks and
>>> not
>>> with every tag related to table as is happening in the code indicated.
>>> Please help how to ensure that the blank lines are not appearing in the
[...]
[...]
Quote:
Quote:

>> Output:
>>
>> === replCrLfHtml: replace CrLf in HTML =====================
--- no <br /> here
Quote:
Quote:

>> This is the starting text (CrLf should not be changed)
>> <table cellspacing="0">
>> <tbody>
>> <tr>
>> <td width="50">S No</td>
>> <td width="185">Name</td>
>> <td width="261">Unit</td>
>> </tr>
>> </tbody>
>> </table>
--- <br /> after each line
Quote:
Quote:

>> This is the first line (paragraph?) of the plain text<br />
>> section; CrLf should be changed to <br /> (& CrLf?).<br />
>> This is the second line (paragraph?) of the plain text<br />
>> section; CrLf should be changed to <br /> (& CrLf?).<br />
[...]
My System SpecsSystem Spec
Old 05-01-2009   #5 (permalink)
S N


 
 

Re: How to Replace vbcrlf outside html tags in memo field of access database

The solution given by both ekkehard.horner and Todd assume static
configurations in the text- they take care of only the html tag. Is there a
solution which uses regular expressions to take care of any other similar
character sets as well (apart from the html table tag). That solution is
expected to be more elegant and not prone to failure which both the above
solutions are..

uandme72


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:49fac3d8$0$32669$9b4e6d93@xxxxxx-online.net...
Quote:

>S N schrieb:
Quote:

>> Few issues with your solution:
>> 1. File system object not permitted by my ISP. HEnce cannot be used in
>> the code.
>
> The FSO is used just for the demo. As I don't have your .mdb, I had to get
> some text to work on from somewhere. It's not needed for my proposal:
> split
> the text at the *logical* boundary (closing table tag) to be able to apply
> the replace operation on the 'plain text' section only.
>
> The differences to Todd Vargo's solution:
>
> (1) con: two ops (split and replace)instead of just one (replace)
> (so perhaps you should use his approach)
> (2) pro: no risk of skipping a ">" at the end of a line in the
> second part
> (depending on your data, this may be a very slim risk)
>
Quote:

>> 2. Actually I want to replace all VBCRLF which appear in paragraph and
>> not those VBCRLF which appear as a line change character as in the
>> structure of any html table. The following is the sample text where I
>> dont need VBCRLF replacement (after <tbody> or after <tr> or after</td>
>> etc).
>>
>>
>> <tbody>
>> <tr>
>> <td width="50">S No</td>
>> <td width="185">Name</td>
>> <td width="261">Unit</td>
>>
>> Whereas I need VBCRLF replacement in the following text:
>> My name is ABC DEF.
>> His name is FGHU HEEN.
>>
>> VBCRLF after the string DEF. should be replaced by <BR />
>>
>
> While there is certainly room for improvement of specification (lines <>
> paragraphs (<p>)) and implementation (no </br > on the last line?), I
> still claim that my code does just that.
>
> [...]
Quote:

>> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
>> news:49f95baa$0$32680$9b4e6d93@xxxxxx-online.net...
Quote:

>>> S N schrieb:
>>>> I am storing text formatted as HTML table alongwith text in many
>>>> paragraphs
> [...]
Quote:
Quote:

>>>> I want that <BR> tags should be inserted only with paragraph marks and
>>>> not
>>>> with every tag related to table as is happening in the code indicated.
>>>> Please help how to ensure that the blank lines are not appearing in the
> [...]
> [...]
Quote:
Quote:

>>> Output:
>>>
>>> === replCrLfHtml: replace CrLf in HTML =====================
> --- no <br /> here
Quote:
Quote:

>>> This is the starting text (CrLf should not be changed)
>>> <table cellspacing="0">
>>> <tbody>
>>> <tr>
>>> <td width="50">S No</td>
>>> <td width="185">Name</td>
>>> <td width="261">Unit</td>
>>> </tr>
>>> </tbody>
>>> </table>
> --- <br /> after each line
Quote:
Quote:

>>> This is the first line (paragraph?) of the plain text<br />
>>> section; CrLf should be changed to <br /> (& CrLf?).<br />
>>> This is the second line (paragraph?) of the plain text<br />
>>> section; CrLf should be changed to <br /> (& CrLf?).<br />
> [...]

My System SpecsSystem Spec
Old 05-02-2009   #6 (permalink)
James Whitlow


 
 

Re: How to Replace vbcrlf outside html tags in memo field of access database

"S N" <uandme72@xxxxxx> wrote in message
news:O98kWunyJHA.5460@xxxxxx
Quote:

> The solution given by both ekkehard.horner and Todd assume static
> configurations in the text- they take care of only the html tag. Is there
> a solution which uses regular expressions to take care of any other
> similar character sets as well (apart from the html table tag).
As Todd commented below, "BTW, it would help if OP would provide a more
concise piece of html to work
with..." This would really help if you could post a larger block of HTML
code with explanations of what needs to be replaced and what does not. There
are a few of us in the group that work with regular expressions regularly &
might be able to provide a pattern(s) that could do that you want.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Replace data in html VB Script
Save Data Field in an Access database .NET General
Disable tagging photo's to DataBase so all users can use the tags. Vista music pictures video
'tags' field embedded in metadata Vista file management
'tags' field embedded in metadata Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46