Do you have the need to make an Table for an forum?
With this script you can convert comma separated text
into BB code formated text.

This script is an simple search and replace thing.
It puts in front of the text an bb code for [TABLE]
and to the start of each line the code [TR] and [TD].
Then it search for your separator like comma and replace this with [/TD][TD]
.... and so on....


Take an look in the code and see the line:
[color=blue]Const mySEPARATOR = ","[/color]
where you can modify your separator.

An improvement like
[color=blue]mySEPARATOR = InputBox[/color]
is also thinkable.

.

.
_The VBS script code for PSPad:_

' 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
http://www.donationcoder.com/Forums/bb/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
'*******************************************************************************

' Split function
'       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




-- 
<http://forum.pspad.com/read.php?2,40666,40666>
PSPad freeware editor http://www.pspad.com

Odpovedet emailem