Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder luigicannavaro's Avatar
    Join Date
    Aug 2007
    Posts
    150
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Cool Output like a list

    Hi,

    How I do an output of a (table with large strings) into a list of single words?
    (no full points, brackets, commas, etc.)

    Example

    from:
    I wouldn't be president if I kept drinking. You get sloppy, can't make decisions, it clouds your reason, absolutely. I still remember the feeling of a hangover, even though I haven't had a drink in twenty years." He said he ate chocolate in the evenings after he swore off booze, because his body missed the sugar.
    TO:


    a
    a
    absolutely
    after
    ate
    be
    because
    body
    booze
    can't
    chocolate
    clouds
    decisions
    drink
    drinking
    even
    evenings
    feeling
    get
    had
    hangover
    haven't
    He
    he
    he
    his
    I
    I
    I
    I
    if
    in
    in
    it
    kept
    make
    missed
    of
    off
    president
    reason
    remember
    said
    sloppy
    still
    sugar
    swore
    the
    the
    the
    though
    twenty
    wouldn't
    years
    You
    your
    Thank you

    Luigi

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    you could use the Split() function (similar to explode with php) and split by the space then for each the array and print out the results.

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    I can tell you how to get a simple list, but array ordering (moving the items into the order you want above) is going to take a lot of work.

    To get a simple list, do this:

    Code:
    <%
    Function killChars(strWords)
    	dim badChars
    	dim newChars
    		badChars = array("!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", ",", "+", "-", "=", "~", "`", "[", "]", "{", "}", """", ";", ":", "<", ">", "?", ",", ".", "/", "|", "\")
    		newChars = strWords
    	for i = 0 to uBound(badChars)
    		newChars = replace(newChars, badChars(i), "")
    	next
    	killChars = newChars
    end function 
    
    strText = objRS("your_database_record")
    '
    strWords = killChars(strText)
    '
    arrText = split(strWords," ")
    '
    for x = 0 to ubound(arrText)
      response.write(arrText(x) & "<br />" & vbCrLf)
    next
    %>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • Users who have thanked Daemonspyre for this post:

    luigicannavaro (09-06-2007)

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    This might be how I'd do it:

    Code:
    <script language="JScript" runat="server">
    function SortVBArray(arrVBArray) {
    	return arrVBArray.toArray().sort().join('\b');
    }
    </script>
    
    <%
    Function SortArray(arrInput)
    	SortArray = Split(SortVBArray(arrInput), Chr(8))
    End Function
    
    dim sSentence, oRE, sText, aWords
    sSentence = "I wouldn't be president if I kept drinking. You get sloppy, can't make decisions, it clouds your reason, absolutely. I still remember the feeling of a hangover, even though I haven't had a drink in twenty years. He said he ate chocolate in the evenings after he swore off booze, because his body missed the sugar."
    set oRE = new RegExp
    oRE.Pattern = "[^a-zA-Z0-9\'\s]"
    oRE.Global = True
    sText = oRE.Replace(sSentence , "")
    set oRE = nothing
    aWords = split(sText, " ")
    if isArray(aWords) then
    	aSortedWords = SortArray(aWords)
    	for i=lBound(aSortedWords) to uBound(aSortedWords)
    		response.write(aSortedWords(i) & "<br/>" & vbCrLf)
    	next
    end if
    %>

    I've just c&p'd an array-sorting method from 4guysfromrolla - it doesn't seem to be quite right but a quick google for "VBScript sort array" isn't going to leave you short of alternatives. Either way, approach stays the same: use a regexp to strip out anything except alphanumeric and whitespace (I wouldn't trust my regexps too much but it seems to do the job here), create an array by splitting on the whitespace... after that you can do pretty much what you like with it. Any use?

  • Users who have thanked Spudhead for this post:

    luigicannavaro (09-06-2007)

  • #5
    Regular Coder luigicannavaro's Avatar
    Join Date
    Aug 2007
    Posts
    150
    Thanks
    11
    Thanked 0 Times in 0 Posts
    SpudHead and DaemonSpyre,

    1. Both scripts works fine.
    2. The script of Spudhead does the sort of string very nice
    3. However the Spudhead script´s don´t the sort of output data of a table. Just output like single words, but not in sort order.
    4. Indeed I beleve in DaemonSpyre "(...) but array ordering (moving the items into the order you want above) is going to take a lot of work".
    5. I remember in Dbase languages (Dbase, Clipper, FoxPro and Visual FP) there is a function called "total to()". Thus (like Jimmy Neutron) I think, think, think... and perhaps the solution would be "insert" the list of words in another table - first step. 2nd step - insert the list of sorted words (from 2nd table) in 3rd. table with its frecuencies together.

    My reasoning is right?

    Thanks for all.


    Luigi

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Your reasoning is correct, but there are multiple other options.

    Here's a version of an ASP sorter for you...

    Try this:

    Code:
    <%
    Function killChars(strWords)
    	dim badChars
    	dim newChars
    		badChars = array("!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", ",", "+", "-", "=", "~", "`", "[", "]", "{", "}", """", ";", ":", "<", ">", "?", ",", ".", "/", "|", "\")
    		newChars = strWords
    	for i = 0 to uBound(badChars)
    		newChars = replace(newChars, badChars(i), "")
    	next
    	killChars = newChars
    end function 
    
    strText = "I wouldn't be president if I kept drinking. You get sloppy, can't make decisions, it clouds your reason, absolutely. I still remember the feeling of a hangover, even though I haven't had a drink in twenty years."" He said he ate chocolate in the evenings after he swore off booze, because his body missed the sugar."
    '
    strWords = killChars(strText)
    '
    arrText = split(strWords," ")
    '
    max = ubound(arrText)
    
    For i = 0 to max
       For j = i+1 to max 
          if LCASE(arrText(i)) > LCASE(arrText(j)) then			'Here, if you want DESC order, change the > to a <
              TemporalVariable = arrText(i)
              arrText(i) = arrText(j)
              arrText(j) = TemporalVariable
         end if
       next 
    next 
    
    response.write("The sorted values are these ones: <br />" & vbCrLf) 
    
    for i=0 to max 
      response.write (arrText(i) & "<br />" & vbCrLf)
    next 
    %>

    Couple items of note:

    1) If this is for your homework, George (CF Admin) is going to kill me...

    2) Notice the LCASE line above. The reason for this is that STRING arrays are sorted first by CASE, then by letter. If you take out the LCASE, you will get all uppercase words first, then all lowercase words.

    3) There is a comment on how to change the sorting by ASC or DESC.

    HTH!
    Last edited by Daemonspyre; 09-06-2007 at 02:23 PM.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #7
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    1) If this is for your homework, George (CF Admin) is going to kill me...
    I remember this assignment from a few years ago. Except mine was supposed to load a text file in Java and display it.
    My Website: DumpsterDoggy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •