string in rtf
string in rtf
(OP)
Hi,
I've a variable that contains a string in rtf format..
Is it possible using vbs to decode this string in txt "standard"?
THANKS
I've a variable that contains a string in rtf format..
Is it possible using vbs to decode this string in txt "standard"?
THANKS
RE: string in rtf
Assuming it is straight text, and you are parsing the string,
1) Look for {
2) Inside the { will be keywords followed by \. These are the tokens that are space terminated.
3) Skip all the { and tokens until you come to something that does not begin with \. This is the text you require.
4) Extract until you get to }
5) Skip the rest
RE: string in rtf
tahnks for your answer..
The string is like this:
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs20 test to clean words
\par }
I don't know how can I parse and clean it..
I would like to extract only this text "test to clean words"..The tags may change if I have a bold string format etc
THANKS
RE: string in rtf
From where are you getting that string?
RE: string in rtf
it's a sql field
RE: string in rtf
RE: string in rtf
First, the Powershell script (note that by default Powershell scripts are disabled for security reasons. Follow the instructions on this page to enable RemoteSigned execution policy), which you should save as "cleanrichtext.ps1"
CODE
# cleanrichtext.ps1 # Author: Mike Strong # Datew: 5 Dec 2019 # Simple example of converting RTF to plain text for tek-tips param ( # default rtf if argument not passed [string]$in = "{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\fs20 example only\par }" ) Add-Type -AssemblyName System.Windows.forms # make sure assembly is available $rtfBox = New-Object System.Windows.Forms.RichTextBox try # see if we can parse the rtf successfully { $rtfBox.rtf=($in) } catch { $rtfBox.text="Source is badly formed rich text" # oops, not good RTF } Write-Output $rtfBox.Text
Now the example VBScript that leverages the powershell script:
CODE
' Author: Mike Strong ' 05 Dec 2019 ' Example for converting RTF into plain text using powershell from VBScript pscommand = "d:\downloads\ps_scripts\cleanrichtext.ps1" ' the powershell script rtf="'{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\fs20 test to clean words\par }'" cmd = "powershell " & pscommand & " -in " & rtf ' Warning: maximum commandline length 8190 characters Set shell = CreateObject("WScript.Shell") Set exec = shell.Exec(cmd) exec.StdIn.Close strPlainText=exec.StdOut.ReadAll MsgBox strPlainText
Note that this will briefly flash the powershell console window
RE: string in rtf
thanks for your help..
It works with you vbs but if I run it on my variable (that contains my rtf..I've always the warning "Source is badly formed rich text" as it cannot recognize the rtf format
All my fields are like that:
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}} \viewkind4\uc1\pard\fs20 AAAAA \par }
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}} \viewkind4\uc1\pard\fs16 testssssssssssss dddd dddddd PDF/EXCEL ddddddd.\fs20 \par }
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}} \viewkind4\uc1\pard\fs20 bbbbbbbbbbbbbb. \b BX 1500 \par \b0 bjjjjjjjjjjjjjjjj. \par }
RE: string in rtf
RE: string in rtf
If ObjAdoDbRecordSet_10.EOF=False Then
DESCRESTESA=ObjAdoDbRecordSet_10("DESCRESTESA")
'-------------------
pscommand = "N:\cleanrichtext.ps1" ' the powershell script
rtf=ObjAdoDbRecordSet_10("DESCRESTESA")
cmd = "powershell " & pscommand & " -in " &rtf ' Warning: maximum commandline length 8190 characters
Set shell = CreateObject("WScript.Shell")
Set exec = shell.Exec(cmd)
exec.StdIn.Close
DESCRESTESA=exec.StdOut.ReadAll
MsgBox "DESCRESTESA "&DESCRESTESA
'--------------
End If
THANKS!!!!!!!!!!!!!!!!!!!!!
RE: string in rtf
CODE
rtf="'{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\fs20 test to clean words\par }'"
So try
CODE
rtf = "'" & ObjAdoDbRecordSet_10("DESCRESTESA") & "'"
RE: string in rtf
thanks!!!!!!!!!!!!!!!