Results 1 to 6 of 6

Thread: Mixed Case Formatter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Mixed Case Formatter

    I ended up with two versions. Instead of confusing things, I will post here just one which I think is the best way to go.
    First the code followed by usage:
    Uses "ui"
    Uses "File"
    Uses "Console"
    Dim Source , List As String
    Dim Filter , s , l As String
    Dim lcs, lcl As String
    Dim SourceNumLines , x , i , ListNumLines As Long
    
    Filter = "ThinBasic Files ( *.tBasic , *.tBasicc ) |*.tBasic;*.tBasicc|"
    Filter += "All Files ( *.* ) |*.*"
    Source = Dialog_OpenFile ( 0 , "Open a Source File" , Dir_GetCurrent , Filter , "tBasic" , %Ofn_FileMustExist Or %Ofn_HideReadOnly Or %Ofn_EnableSizing ) 
    List = App_SourcePath + "MixedCaseWordListv2.txt"
    
    Dim Sources As String Value File_Load ( Source ) 
    Dim Lists As String Value File_Load ( List ) 
    Dim FileOut As String Value "OutFileMixedCase.txt"
    Dim OutPutText As String
    Dim SourceLines ( ) , ListLines ( ) As String
    
    Dim Count As Long
    Dim pos As Long Value -1
    Dim nTimes As dWord = 1
    
    SourceNumLines = ParseCount ( Sources , $crlf ) 
    SourceNumLines = Parse ( Sources , SourceLines , $crlf ) 
    
    ListNumLines = ParseCount ( Lists , $crlf ) 
    ListNumLines = Parse ( Lists , ListLines , $crlf ) 
    
    For Count = 1 To SourceNumLines
     Console_Cls
     Print "Working" + $crlf
     Print Count + " / " + SourceNumLines
     For x = 1 To Len ( SourceLines ( Count ) ) 
      SourceLines ( Count ) = lCase$ ( SourceLines ( Count ) )
     Next
     s = SourceLines ( Count ) 
      For i = 1 To ListNumLines
        l = ListLines(i)
        lcs = lCase$(s)
        lcl = lCase$(l)
        While pos < Len(s)
         pos = Instr( lcs , lcl ,nTimes)
         If pos > 0 Then
          Mid$(s,pos,Len(l)) = ListLines(i)
          Incr nTimes
         End If
         If pos = 0 Then Exit While
        Wend
        pos = -1
        nTimes = 0
      Next
      OutPutText += s + $crlf  
    Next
    File_Save ( App_SourcePath + FileOut , OutPutText )
    
    This program will ask you to open the script file you want to convert to mixed case.
    It will then use "MixedCaseWordListv2.txt" to format your script and
    put the a new file to "OutFileMixedCase.txt"

    The beauty of this work flow is that all the complicated logic that would be involved is all handled by your word list.
    I will attach an example list that is by no mean complete. But at least you can get an idea of how your list should be created and maintained.
    Basically, override of previous words is done by how much further down the list the word is located.
    So short words which appear often and will mess up the look: as to if on
    will get overwritten when needed by
    was ton gif won
    which can be overwritten by words further down the list
    wash button gift wonder

    to make things easy, the attached file has a msworks spreadsheet. MSworks comes for free on all xp machines as far as I know.
    I set up a simple sheet which takes your word list, column b and puts the length of the word in column a
    Just add words to the bottom of your list.
    Use fill down to copy the formula into the new rows for column a and then sort
    col a asc
    col b asc
    Then select all your words in column b and paste them into "MixedCaseWordListv2.txt"

    Probably seems a lot more scary than it is actually to do.
    Attached Files Attached Files

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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