Jump to content

Recommended Posts

Posted

i want change the first line in my sample.txt

sample data:

apple 100

banana 50

orange 150

I want to change the value from the apple line of text if the value (apple 100 to apple 250) change with a value apple 180 ... It`s possible..??

This is my script :

#include <file.au3>
#include <array.au3>
_sample()
Func _sample()
    Local $sample[1]
    Local $n, $iChange = 0
    If _FileReadToArray("sample.txt", $sample) Then
        For $n = 1 To $sample[0]
            If StringInStr($sample[$n], "apple 100") Then
                $sample[$n] = StringReplace($sample[$n], "apple 100", "apple 150")
                $iChange = 1
            EndIf
        Next
    EndIf
If $iChange Then _FileWriteFromArray("sample.txt", $sample, 1) 
EndFunc

But Only Replace the value apple 100 to apple 150..

I hope this is a good day. I can get opinions from the people in this forum ..

Posted (edited)

I'm not sure I completely understood, but this should change apple 100 - apple 149 to apple 250.

$fileread = StringRegExpReplace($fileread, "apple 1[0-4][0-9]", "apple 250")

There is probably a simpler way, but that's the easiest way I can think of.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Posted

I'm not sure I completely understood, but this should change apple 100 - apple 149 to apple 250.

$fileread = StringRegExpReplace($fileread, "apple 1[0-4][0-9]", "apple 250")

There is probably a simpler way, but that's the easiest way I can think of.

Thank`s.. I hope I'll get a new opinion again..

Please Help me... :D

Posted

It would help if you were to explain exactly what you want/what didn't work.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...