CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2014
    Posts
    4

    Question How can read a line of unicode text file? and how write to a line of unicode text fil

    hi

    i have a text file with format unicodeExample this

    HTML Code:
        ; for 16-bit app support  
          
        [fonts]  
        [extensions]  
        Kill file returned: :3:  
        No Previous IE40, not an IE40 install.  
        Add preclean, crypto and maybe DCOM  
        OS is NT  
        Installing OLEAUT.exe.  
        Architecture is Intel.  
        dispci.dll: ============BEGIN DisplayClassInstaller============  
        dispci.dll: ============BEGIN OnSelectBestCompatDrv============  
        dispci.dll: ============END OnSelectBestCompatDrv==============  
        dispci.dll: DisplayClassInstaller: Returning 0xe000020e for DIF 0x17 and device VMBUS\{DA0A7802-E377-4AAC-8E77-0558EB1073F8}\{5620E0C7-8062-4DCE-AEB7-520C7EF76171}  
        .  
        .  
        .  

    now i how can write a text to line 2? line 2 is free line!

    after write i how can show line 2 in msgbox?!

    thanks

  2. #2
    Join Date
    Jul 2014
    Posts
    4

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    guys i really need your help...

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    Read file in a buffer, then insert the needed text after the first end-of-line (as a second line)
    Victor Nijegorodov

  4. #4
    Join Date
    Jul 2014
    Posts
    4

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    Quote Originally Posted by VictorN View Post
    Read file in a buffer, then insert the needed text after the first end-of-line (as a second line)
    Thanks VictorN
    i test all way but i cant do that!
    Possible give me sample code?
    this is my test file: test.zip
    thanks
    Last edited by r2du-soft; July 23rd, 2014 at 02:15 PM.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    How about Skin-A-Cat?

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim x As Integer, st As String, y As Integer
      Dim ff As Integer
      Dim strBuff As String
      Dim str() As String
      ff = FreeFile
    On Error GoTo trapit
      Open App.Path & "\to do3.txt" For Input As #ff
        strBuff = Input(LOF(ff), ff)
      Close #ff
      ' ----------------- two ways to skin a cat --------------
      MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
      ' -------------------------------------------------------
      str() = Split(strBuff, vbCrLf)
      MsgBox "There are " & UBound(str) + 1 & " lines in the file"
      Dim words() As String
      For x = 0 To UBound(str)
        words = Split(str(x)) ' Split into WORDS
        For y = 0 To UBound(words)
          st = st & str(x) & vbCrLf & vbCrLf ' one line for each word
        Next y
      Next x
      MsgBox st
      Exit Sub
    trapit:
      If Err.Number = 53 Then
       MsgBox ("Didn't work")
      End If
    End Sub
    Last edited by dglienna; July 23rd, 2014 at 05:36 PM. Reason: Posted over 8,000 times!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2014
    Posts
    4

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    Quote Originally Posted by dglienna View Post
    How about Skin-A-Cat?

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim x As Integer, st As String, y As Integer
      Dim ff As Integer
      Dim strBuff As String
      Dim str() As String
      ff = FreeFile
    On Error GoTo trapit
      Open App.Path & "\to do3.txt" For Input As #ff
        strBuff = Input(LOF(ff), ff)
      Close #ff
      ' ----------------- two ways to skin a cat --------------
      MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
      ' -------------------------------------------------------
      str() = Split(strBuff, vbCrLf)
      MsgBox "There are " & UBound(str) + 1 & " lines in the file"
      Dim words() As String
      For x = 0 To UBound(str)
        words = Split(str(x)) ' Split into WORDS
        For y = 0 To UBound(words)
          st = st & str(x) & vbCrLf & vbCrLf ' one line for each word
        Next y
      Next x
      MsgBox st
      Exit Sub
    trapit:
      If Err.Number = 53 Then
       MsgBox ("Didn't work")
      End If
    End Sub
    thanks dglienna
    but not work on the Unicode file!
    I put a sample Of files in post #4
    please test on that

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    Quote Originally Posted by r2du-soft View Post
    thanks dglienna
    but not work on the Unicode file!
    Define "not work".
    Victor Nijegorodov

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How can read a line of unicode text file? and how write to a line of unicode text

    You'd need to split that line on ':' and also '\'
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured