Jump to content

Recommended Posts

Posted

I have hundreds of line like this below

Snaketongue [Jezyk Weza]\nSnake Tongue

I need to delete [Jezyk Weza] in each lines

possible?

This world is crazy

Posted

Yes Possible.

$sText = "Snaketongue [Jezyk Weza]\nSnake Tongue"
 MsgBox(0, "Result", _DeleteBetween($sText))

Func _DeleteBetween($sText)
     Local $sLeft = StringLeft($sText, StringInStr($sText, "[")-1)
     Return $sLeft & StringTrimLeft($sText, StringInStr($sText, "]"))
EndFunc
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Posted

$file = FileOpen("C:\Users\Flames\Desktop\Y.txt", 2)

For $i = 1 To 2830
     $sText = FileReadLine($file, $i)
     _DeleteBetween($sText)
     ToolTip($i & " / 2830")
 Next
 
 FileClose($file)
 
Func _DeleteBetween($sText)
     Local $sLeft = StringLeft($sText, StringInStr($sText, "[")-1)
     Return $sLeft & StringTrimLeft($sText, StringInStr($sText, "]"))
 EndFunc

Hmm deleted all text in file :mellow:

I have backup of file, but why this wont work? :P

This world is crazy

Posted (edited)

K edited and working code

#include <file.au3>

$file = "C:\Users\Flames\Desktop\Y.txt"

for $i = 1 To 2820 Step +1
    $text = FileReadLine($file, $i)
    _DeleteBetween($Text, $file)
Next
 
Func _DeleteBetween($sText, $file)
     Local $sLeft = StringLeft($sText, StringInStr($sText, "[")-1)
     Return _FileWriteToLine($file, $i, $sLeft & StringTrimLeft($sText, StringInStr($sText, "]")),1)
 EndFunc

Edit: This deleted some lines, :mellow:

Edited by Sobiech

This world is crazy

Posted

$sStr = FileRead(SomeFile.txt)
$sStr = StringRegExpReplace($sStr, "\[.+?\]", "")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

$sStr = FileRead(SomeFile.txt)
$sStr = StringRegExpReplace($sStr, "\[.+?\]", "")

Hmmm wont work :P

i tried

$file = "C:\Users\Flames\Desktop\Y.txt"
For $i = 1 To 2820 Step +1
$line = FileReadLine($file, $i)
StringRegExpReplace($line, "\[.+?\]", "")
ToolTip($i)
Next

but same effect

One more code

#include <file.au3>

$file = "C:\Users\Flames\Desktop\Y.txt"
Dim $aRec
$array = _FileReadToArray($file, $aRec)

For $i = 0 To $aRec[0] Step +1
StringRegExpReplace($aRec[$i], "\[.+?\]", "")
Next

ToolTip($aRec[1730])
Sleep(2000)

and wont work

Maybe this show more ideas "how to" :mellow:

Edited by Sobiech

This world is crazy

Posted (edited)

$file = FileOpen("C:\Users\Flames\Desktop\Y.txt", 2)

Hmm deleted all text in file 
I have backup of file, but why this wont work? 

Thats becauseyou opened the file using mode 2 which is 'Write mode (erase previous contents)'.

As JohnOne said your using functions and not storing there output in a variable which you then use in some way.

Think about how you want to tackle this problem a bit.
1. read contents of file
2. change part of each line
3. write changed lines to file

If you understand arrays you could do the following:-
1. _FileReadToArray = read the contents of the file into an array
2. loop the through the array using either the function i gave or the StringRegExpReplace GEOSoft provided to actually change the values of the array
3. _FileWriteFromArray = write the contents of your array into a file, either overwrite the original file or make a new version moving the old to a temp place incase the new one failed for some reason.


            
                


    Edited  by Yoriz
    
    

            
        

        

        
            

    
        

        
            
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
        
    

        
    

    
    

    

                    
                    
                        
                    
                    
                

                    

                    
                    






    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


GEOSoft
            
            
                Posted 
                
            
        
    
    
        


GEOSoft
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                MVPs
                
                    
                
            
            
                
                    
                        
                            
                                
                            
                                 10.3k
                            
                                
                            
                        
                        
                    
                
            
            
                

    
    
        
Sure I'm senile. What's your excuse?
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
           
           Posted 
           
            
            
                
                    (edited)
                
                
            
        
    

    

    

    
        
        
            Just too simple$file = "C:\Users\Flames\Desktop\Y.txt"
$sStr = FileRead($File)
$sStr = StringRegExpReplace($sStr, "\[.+?\]", "")
If @Extended Then
    $hFile = FileOpen($File, 2)
    FileWrite($hFile, $sStr)
    FileClose($hFile)
EndIf

If you want to test regular expressions to make sure they are doing what you want, look in my signature for the PCRE Toolkit.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...