Parse Text without splitting words by Luke Latimer

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
October 08, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

******************************
'**************************************************
'*     Script written by:     Luke Latimer
'*     on:                     18/09/2000
'*
'*    Name:                 ParseText.vbs
'*     Description:
'*                         This script consists of a function (ParseText) that
'*                         takes as parameters a string, and a number, and a
'*                         Line Break delimiter (can be VbCrlf).
'*                         The output is the text containing the delimiter according to the
'*                         value passed. If there are spaces present in the text
'*                         The function will attempt to avoid splitting words.
'*                         Use arr=Split(ParsedText,Delimiter) to extract the lines from the output.
'*
'****************************************************

Dim Text, WrapAt, Delimiter
WrapAt=80
Delimiter="#Delimiter#"

'For use when testing with WSH
'text=inputbox("Enter some text, if it's bigger than " & WrapAt & " chars then it will be wrapped onto the next line")

myText=Request.Form("TheTextBox_or_Area") 'Or load from DB

myTextArr=Split(ParseText(myText, WrapAt, Delimiter), Delimiter)

For i=0 to UBound(myTextArr)
    Response.Write myTextArr(i) & "<BR>"
Next


FUNCTION ParseText(Text,WrapAt,Delimiter)

If len(text)>WrapAt then 'start wrapping it

Dim index
index=0

    Do While Len(Text)>WrapAt
'don't wrap the text halfway through a word if it can be helped

    If Instr(Left(Text,WrapAt)," ")=0 Then 'No spaces, split words?

        If ParseText="" Then
            ParseText= Left(Text,WrapAt)
        Else
            ParseText=ParseText & Delimiter & Left(Text,WrapAt)
        End if

        If Len(Text)> WrapAt Then
            Text=Right(Text,Len(Text)-WrapAt)
                       
                If Len(Text)<=WrapAt Then
                    If ParseText="" Then
                        ParseText= Text
                    Else
                        ParseText=ParseText & Delimiter & Text
                    End if
                End if
        End if

    Else

        tempText=Left(Text,WrapAt)
        SplitAt=Instr(strReverse(tempText)," ")
       
        If SplitAt>0 Then Buffer=1
       
        If SplitAt=WrapAt Then
            If ParseText="" Then
                ParseText=TempText
            Else
                ParseText=ParseText & Delimiter & TempText
            End if
        Else
            If ParseText="" Then
                ParseText=Left(tempText,Len(tempText) -SplitAt+Buffer)
            Else
                ParseText=ParseText & Delimiter & Left(tempText,Len(tempText) -SplitAt+Buffer)
            End if
        End if

        If Len(Text)>WrapAt Then
            If SplitAt=WrapAt Then
                Text=Right(Text,Len(Text)-WrapAt)
            Else
                Text=Right(Text,Len(Text)-(WrapAt-SplitAt+Buffer))
            End if
           
            If Len(Text)<=WrapAt Then
                If ParseText="" Then
                    ParseText=Text        
                Else
                    ParseText=ParseText & Delimiter & Text
                End if
            End if
        End if        
       
   
    End if
    Index=Index+1
    Loop
   
Else

    ParseText=Text

End if

End FUNCTION
******************************
blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials