Hello all,

Another search - this one provides you with simple access to wrapping
text (such as text you are responding to from an email) and prepending
a character string to it. Options include removing existing prepended
characters, setting the length of each line and whether to remove an
existing prepended value (carriage return + "> ").

Regards,

Shawn K. Hall
http://ReliableAnswers.com/

'// ========================================================
    "I have made myself what I am."
       -- Tecumseh
<search function="wrap">
  <name>Wrap Clipboard Text</name>
  <description>
    Wraps the contents of the clipboard to a certain number of characters,
    inserting optional prefix and places it back onto the clipboard.<br />
    <div class="helpboxDescLabels">Usage:</div>
    <table class="helpboxDescTable">
      <tr><td>wrap <strong>[/pre <em>&lt;prefix&gt;</em>] [/max <em>&lt;num&gt;</em>] [/no]</strong></td></tr>
    </table>
    <div class="helpboxDescLabels">Switches:</div>
    <table class="helpboxDescTable">
      <tr><td>/pre</td><td> &gt;  </td><td>Prefix each line with this string</td></tr>
      <tr><td>/np</td><td> - </td><td>Disable line prefixing</td></tr>
      <tr><td>/max</td><td> 64 </td><td>Maximum characters per line</td></tr>
      <tr><td>/no</td><td> False </td><td>Prevent removal of \n'&gt; '</td></tr>
    </table>
    <div class="helpboxDescLabels">Example:</div>
    <table class="helpboxDescTable">
      <tr><td>wrap</td></tr>
      <tr><td>wrap /no /max 65</td></tr>
      <tr><td>wrap /pre &gt; /max 76</td></tr>
      <tr><td>wrap /pre // /max 72</td></tr>
      <tr><td>wrap /pre -- /max 30</td></tr>
      <tr><td>wrap /pre REM /no</td></tr>
      <tr><td>wrap /np /max 10000</td></tr>
    </table>
  </description>
  <category>Functions</category>
  <link>http://www.ReliableAnswers.com/</link>
  <contributor>Shawn K. Hall</contributor>
  
  <form name="wrapf"
    action="http://reliableanswers.com/x/";
    method="post">
    <input type="hidden" name="q" value="" />
    <textarea name="vbscode" style="display: none;"><![CDATA[

Dim lq, lqe, q, qsPrefix, qlMax, qbNoRemove
q = document.wrapf.q.value
lq = InStr( 1, q, "/np", 1)
If lq > 0 Then
  qsPrefix = ""
Else
  lq = InStr( 1, q, "/pre", 1)
  If lq > 0 Then
    lqe = InStr( lq + 1, q, "/", 1)
    If lqe > 0 Then
      lqe = lqe - (lq + 5)
      qsPrefix = Mid( q, lq+5, lqe )
    Else
      qsPrefix = Mid( q, lq+5 )
    End If
  Else
    qsPrefix = "> "
  End If
End If
lq = InStr( 1, q, "/max", 1)
If lq > 0 Then
  lqe = InStr( lq + 1, q, "/", 1)
  If lqe > 0 Then
    lqe = lqe - (lq + 5)
    qlMax = CLng(Trim(Mid( q, lq+4, lqe )))
  Else
    qlMax = CLng(Trim(Mid( q, lq+4 )))
  End If
Else
  qlMax = 64
End If
lq = InStr( 1, q, "/no", 1)
If lq > 0 Then
  qbNoRemove = True
Else
  qbNoRemove = False
End If
q = ClipBoardGetText
q = Wrap( q, qsPrefix, qlMax, qbNoRemove )
ClipBoardSetText( q )

Function Wrap(ByVal sString, sPrefix, sMax, bRemove)
  Dim sBuild, lLast, lLen
  lLen = Len(sPrefix)
  sMax = sMax - lLen
  If bRemove Then
    While InStr(1, sString, vbCrLf & "> ", 1)
      sString = Replace(sString, vbCrLf & "> ", vbCrLf, , , 1)
    Wend
    While InStr(1, sString, vbCrLf & " ", 1)
      sString = Replace(sString, vbCrLf & " ", vbCrLf, , , 1)
    Wend
  End If
  sString = Replace(sString, vbCrLf & vbCrLf, " {|} ")
  sString = Replace(sString, vbCrLf, " ")
  While InStr(sString, "  ")
    sString = Replace(sString, "  ", " ")
  Wend
  sString = Replace(sString, "{|}", vbCrLf & sPrefix) & " "
  While Len(sString) > 0
    If InStrRev(sString, vbLf, sMax, 1) <> 0 Then
      lLast = InStrRev(sString, vbCrLf, sMax, 1) + 2
    ElseIf sMax >= Len(sString) Then
      lLast = Len(sString)
    Else
      lLast = InStrRev(sString, " ", sMax + 1, 1)
    End If
    sBuild = sBuild & vbCrLf & sPrefix & Mid(sString, 1, lLast)
    sString = Mid(sString, lLast + 1)
  Wend
  Wrap = sBuild
End Function
Function ClipBoardSetText( sText )
  ClipBoardSetText = window.clipboardData.SetData( "Text", sText )
End Function
Function ClipBoardGetText()
  ClipBoardGetText = window.clipboardData.GetData( "Text" )
End Function

    ]]></textarea>
  </form>

  <script><![CDATA[

  function wrap (q)
  {
    document.wrapf.q.value = q;

  //get the vbs code
    var wrapt = "";
    wrapt = document.wrapf.vbscode.value;

  //remove CDATA prefix and trailer
    wrapt = wrapt.replace( /(\<\!\[CDATA\[)/g, '' ).replace( /(\]\]\>)/g, '' );

  //trim it
    wrapt = wrapt.replace(/^\s+/g, '' ).replace(/\s+$/g, '' );

  //run the script
    window.execScript( wrapt, "vbscript" );

  //return
    return ( true );
  }

  ]]></script>
  <copyright>
	Copyright (c) 2002 David Bau
	Distributed under the terms of the
	GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>

Reply via email to