Jump to content

Recommended Posts

Posted

$sFile = @ScriptDir & '\MyTest.txt'
$sText = FileRead($sFile)
$hFile = FileOpen($sFile, 2)

FileWrite($hFile, StringRegExpReplace($sText, '\r\n', '0'&@CRLF, 9))
FileClose($hFile)

#cs
    #### MyTest.txt content: ####       #### MyTest.txt content (modified): ####
        1                                   10
        2                                   20
        3                                   30
        4                                   40
        5                                   50
        6                                   60
        7                                   70
        8                                   80
        9                                   90
        10                                  10
        11                                  11
        12                                  12
        13                                  13
        14                                  14
        15                                  15
#ce

Not a good idea for big files, if applicable.

Posted

alternatively, filewriteline() with a for/next loop would also work, and would be the simplest, but would only work if you needed to write the first 9 lines in order and didn't have to edit specific lines, otherwise the ini functions would be best

[u]You can download my projects at:[/u] Pulsar Software
Posted

$sFile = @ScriptDir & '\MyTest.txt'
$sText = FileRead($sFile)
$hFile = FileOpen($sFile, 2)

FileWrite($hFile, StringRegExpReplace($sText, '\r\n', '0'&@CRLF, 9))
FileClose($hFile)

#cs
    #### MyTest.txt content: ####       #### MyTest.txt content (modified): ####
        1                                   10
        2                                   20
        3                                   30
        4                                   40
        5                                   50
        6                                   60
        7                                   70
        8                                   80
        9                                   90
        10                                  10
        11                                  11
        12                                  12
        13                                  13
        14                                  14
        15                                  15
#ce

Not a good idea for big files, if applicable.

ok thanks but i dont want to add a 0 i want to over write say a 20 to a 0
Posted

alternatively, filewriteline() with a for/next loop would also work, and would be the simplest, but would only work if you needed to write the first 9 lines in order and didn't have to edit specific lines, otherwise the ini functions would be best

ok so for the for/next loop where do i put the file name etc?
Posted

To replace the first 9 lines with '0':

$sFile = @ScriptDir & '\MyTest.txt'
$sText = FileRead($sFile)
$hFile = FileOpen($sFile, 2)

FileWrite($hFile, StringRegExpReplace($sText, '.*\r\n', '0'&@CRLF, 9)) ; '0'
FileClose($hFile)oÝ÷ Ù:+zZqëayø«²ßew¬Â+aßÝýaxºÚ"µÍÌÍÜÑ[HHØÜ  [È ÌÎNÉÌLÓ^UÝ    ÌÎNÂÌÍÜÕ^H[TXY
    ÌÍÜÑ[JBÌÍÚ[HH[SÜ[   ÌÍÜÑ[KB[UÜ]J   ÌÍÚ[KÝ[ÔYÑ^XÙJ   ÌÍÜÕ^   ÌÎNËÌLÜÌLÛÌÎNË    ÌÎNÉÌÎNËJJHÈÝ[Â[PÛÜÙJ   ÌÍÚ[JoÝ÷ ÙK"¢³^ÆÙh¢®¶­sb6æ6ÇVFRfÇC´fÆRæS2fwC° ¤FÒb33c·4fÆRÒ67&DF"fײb33²b3#´×FW7BçGBb33²Âb33c¶ÆæW0¥ôfÆU&VEFô'&b33c·4fÆRÂb33c¶ÆæW2  ¤f÷"b33c¶ÒFò b33c¶ÆæW5²b33c¶ÒÒb33³b33°¤æW@ ¥ôfÆUw&FTg&öÔ'&b33c·4fÆRÂb33c¶ÆæW2Â
Posted

ok so for the for/next loop where do i put the file name etc?

this would require that you have an array setup with the contents, so it may not be ideal for you, but if it is, this is how it would work:

For $i = 1 to 9
FileWriteLine("yourfilename.txt",$linecontents[$i])
Next
[u]You can download my projects at:[/u] Pulsar Software
Posted

To replace the first 9 lines with '0':

$sFile = @ScriptDir & '\MyTest.txt'
$sText = FileRead($sFile)
$hFile = FileOpen($sFile, 2)

FileWrite($hFile, StringRegExpReplace($sText, '.*\r\n', '0'&@CRLF, 9)) ; '0'
FileClose($hFile)oÝ÷ Ù:+zZqëayø«²ßew¬Â+aßÝýaxºÚ"µÍÌÍÜÑ[HHØÜ  [È ÌÎNÉÌLÓ^UÝ    ÌÎNÂÌÍÜÕ^H[TXY
    ÌÍÜÑ[JBÌÍÚ[HH[SÜ[   ÌÍÜÑ[KB[UÜ]J   ÌÍÚ[KÝ[ÔYÑ^XÙJ   ÌÍÜÕ^   ÌÎNËÌLÜÌLÛÌÎNË    ÌÎNÉÌÎNËJJHÈÝ[Â[PÛÜÙJ   ÌÍÚ[JoÝ÷ ÙK"¢³^ÆÙh¢®¶­sb6æ6ÇVFRfÇC´fÆRæS2fwC° ¤FÒb33c·4fÆRÒ67&DF"fײb33²b3#´×FW7BçGBb33²Âb33c¶ÆæW0¥ôfÆU&VEFô'&b33c·4fÆRÂb33c¶ÆæW2  ¤f÷"b33c¶ÒFò b33c¶ÆæW5²b33c¶ÒÒb33³b33°¤æW@ ¥ôfÆUw&FTg&öÔ'&b33c·4fÆRÂb33c¶ÆæW2Â
thanks for all your help

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...