ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


2 posters

    ช่วยแก้ให้หน่อย

    tomakung
    tomakung
    PSsix Member Class II
    PSsix Member Class II


    ช่วยแก้ให้หน่อย  Empty ช่วยแก้ให้หน่อย  Empty
    จำนวนข้อความ : 38
    ความนิยม : 11
    เข้าร่วมเมื่อ : 24/02/2012

    ช่วยแก้ให้หน่อย  Empty ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by tomakung 10/04/14, 01:20 pm

    มีไฟล์ test.txt

    1
    0
    1
    0
    ต้องการให้เปลี่ยนเป็น
    0
    1
    0
    1
    โดยการแสกนหาค่าถ้า 1 ให้ เป็น 0 ถ้า 0 ให้เป็น 1

    Code:
    $szFile = "test.txt"
    $szText = FileRead($szFile,FileGetSize($szFile))
    $szText = StringReplace($szText,"1", "0")
    $szText = StringReplace($szText,"0", "1")
    FileDelete($szFile)
    FileWrite($szFile,$szText)


    ต้องลงคำสัง if while do เพิ่มยังไง
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by Arm 10/04/14, 01:52 pm

    นี่ครับ ^^
     em233 
    Code:
    Local $str
    $szFile = "test.txt"
    $binary = FileRead($szFile, FileGetSize($szFile))
    If @error Then Exit
    ConsoleWrite("File name: " & $szFile & @CRLF & "== Before ==" & @CRLF & $binary & @CRLF & @CRLF)
    $split = StringSplit($binary, "")
    For $i = 1 To $split[0]
       If $split[$i] = "0" Then
          $str &= "1"
       ElseIf $split[$i] = "1" Then
          $str &= "0"
       ElseIf $split[$i] = @CR Then
          $str &= @CRLF
       EndIf
    Next
    ConsoleWrite("== After ==" & @CRLF & $str & @CRLF)


    ทดสอบ output ที่ได้..
    Code:
    File name: test.txt
    == Before ==
    0000011111
    1100110011
    1010101010
    0101010101

    == After ==
    1111100000
    0011001100
    0101010101
    1010101010

    ชินจัง
    tomakung
    tomakung
    PSsix Member Class II
    PSsix Member Class II


    ช่วยแก้ให้หน่อย  Empty ช่วยแก้ให้หน่อย  Empty
    จำนวนข้อความ : 38
    ความนิยม : 11
    เข้าร่วมเมื่อ : 24/02/2012

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by tomakung 10/04/14, 02:12 pm

    ผมทดสอบแล้วครับไม่มีไรเกิดขึ้นเลยครับ ท่าน
    tomakung
    tomakung
    PSsix Member Class II
    PSsix Member Class II


    ช่วยแก้ให้หน่อย  Empty ช่วยแก้ให้หน่อย  Empty
    จำนวนข้อความ : 38
    ความนิยม : 11
    เข้าร่วมเมื่อ : 24/02/2012

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by tomakung 10/04/14, 02:12 pm

    รึจะเป็นที่ผมใช้ win 8
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by Arm 10/04/14, 03:47 pm

    ตอนนี้คอมที่ทำงานใช้ WinXP แรมกากๆเลยครับ (ขอระบายนิดนึง5555)

    เดี่ยวกลับบ้านจะไปเทสกับ Windows 7 & 8 ให้ครับ

    ปล.ตอนรันมันเด้งออกเลยเหรอครับ เพราะบรรทัดนี้มั้งถ้าเออเร่อให้ออกเลย If @error Then Exit
    tomakung
    tomakung
    PSsix Member Class II
    PSsix Member Class II


    ช่วยแก้ให้หน่อย  Empty ช่วยแก้ให้หน่อย  Empty
    จำนวนข้อความ : 38
    ความนิยม : 11
    เข้าร่วมเมื่อ : 24/02/2012

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by tomakung 10/04/14, 07:27 pm

    ผมกลับมาเทสกับ win7แล้ว โอเคแล้วนะครับ

    ขอบคุณครับ
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    ช่วยแก้ให้หน่อย  Empty Re: ช่วยแก้ให้หน่อย

    ตั้งหัวข้อ by Arm 10/04/14, 07:33 pm

    em218 

      เวลาขณะนี้ 26/04/24, 04:15 pm