' Save this script as e.g. CSV2BBTable.vbs
' into your PSPad script folder, e.g. "C:\Program Files\PSPad\Script\VBscript\CSV2BBTable.vbs"
' Then select some separated text (see mySEPARATOR) and execute this script from the script menu.
' ------------------------------------------------------------------------------
' author : Stefan Schuck 2007 for PSPad.com and DonationCoder.com
' Based on an proof of concept from "Crono" at https://www.donationcoder.com/forum/index.php?topic=8504.msg61390#msg61390
' Use code from : Scott Greenberg <
[email protected]> [GoGoModule.vbs]
' http://gogogadgetscott.info/computers/cc/snippet.php?sid=34
'
Use code from : James Swan [text_to_list.vbs]
' ------------------------------------------------------------------------------
Const module_name = "CSV-2-BBTable"
Const module_ver = "0.001"
Const mySEPARATOR = "," ' the separator in your CSV file to separate the table cells, e.g. , ; :
Sub Init
menuName = "&" & module_name
addMenuItem "Execute &CSV to BBcode Table" , menuName, "replaceRegExp"
addMenuItem "&Open this script file" , menuName, "openFile"
End Sub
Sub openFile
Set obj1 = newEditor()
obj1.openFile(moduleFileName(module_name))
End Sub
' ------------------------------------------------------------------------------
' Text editing.
' ------------------------------------------------------------------------------
Dim arrLines
' Pattern Find
Dim vFind(4)
vFind(0)= "#" 'not needed
vFind(1)= mySEPARATOR
vFind(2)= "$" 'start of each line
vFind(3)= "^" 'end of each line
' newtext Replace
Dim vReplace(4)
vReplace(0) = "[br]"
vReplace(1) = "[/td][td]"
vReplace(2) = "[/td][/tr]"
vReplace(3) = "[tr][td]"
Sub replaceRegExp
'*******************************************************************************
'
author
: James Swan '
Created
: 28 September 2005
'*******************************************************************************
Set editor = newEditor()
With editor
.assignActiveEditor()
strInput = .selText()
End With
If Len(strInput) > 0 Then
arrLines = Split(strInput, vbCrLf)
For L = 0 to UBound(arrLines)
For i = 1 to UBound(vFind)
arrLines(L) = runRegExpReplace(arrLines(L),vFind(i) ,vReplace(i))
Next
Next
strList = "[table]" & vbCrLf
For L = 0 To UBound(arrLines)
strLine = Trim(arrLines(L))
strList = strList & strLine & vbCrLf
Next
strList = strList & "[/table]"
editor.selText strList
Else
MsgBox "Please select some text... ", 0, MODULE_TITLE
End If
Set editor = Nothing
End Sub
' ------------------------------------------------------------------------------
' Private function: Find and replace with RegEx
' ------------------------------------------------------------------------------
' author Scott Greenberg <
[email protected]>
Private Function runRegExpReplace(haystack, Pattern, newtext)
Set regEx = New RegExp
If Pattern = "" Then
runRegExpReplace = haystack
Exit Function
End If
regEx.Pattern = Pattern
regEx.IgnoreCase = TRUE
regEx.Global = TRUE
runRegExpReplace = regEx.Replace(haystack, newtext)
End Function