brNwsH Posted August 5, 2011 Share Posted August 5, 2011 (edited) Hey Com, im new here and i need some help. i searched the forums already and didnt found anything. i have a text file with some textlines. some of these lines have an [xyz] infront of the text. is it possible to search these lines and only delete the clamp + text in between them? thx brN //EDIT i think i got it can be closed Edited August 5, 2011 by brNwsH Link to comment Share on other sites More sharing options...
wakillon Posted August 5, 2011 Share Posted August 5, 2011 Welcome to the forums ! Try #include <String.au3> $_FilePath = 'C:\text.txt' $_FileRead = FileRead ( $_FilePath ) $_NewText = _RemoveBetweenBrackets ( $_FileRead, 1 ) ConsoleWrite ( "!->-- $_NewText : " & $_NewText & @Crlf ) $_file = FileOpen ( $_FilePath, 2 ) FileWrite ( $_file, $_NewText ) FileClose ( $_file ) Func _RemoveBetweenBrackets ( $_Stringg, $_Option=1 ) ; 1 [ ], 2 ( ), 3 { }, 4 < >, 5 ‹ ›, 6 « » Local $_BracketsArray[13] = [12, '[' ,']' ,'(' ,')' ,'{', '}', '<', '>', '‹', '›', '«', '»'] Local $_chr1 = $_BracketsArray[$_Option*2-1], $_chr2 = $_BracketsArray[$_Option*2] $_StringBetweenArray = _StringBetween ( $_Stringg, $_chr1, $_chr2 ) If Not @error Then For $_S = 0 To UBound ( $_StringBetweenArray ) -1 $_StringInStr1 = StringInStr ( $_Stringg, $_chr1 & $_StringBetweenArray[$_S] & $_chr2 ) -1 $_StringInStr2 = StringLen ( $_StringBetweenArray[$_S] ) + 2 $_Stringg = StringLeft ( $_Stringg, $_StringInStr1 ) & StringRight ( $_Stringg, StringLen ( $_Stringg ) - $_StringInStr1-$_StringInStr2 ) Next Else Return $_Stringg EndIf Return StringStripWS ( $_Stringg, 7 ) EndFunc ;==> _RemoveBetweenBrackets ( )It remove all occurences between brackets. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
brNwsH Posted August 5, 2011 Author Share Posted August 5, 2011 Welcome to the forums ! Try #include <String.au3> $_FilePath = 'C:\text.txt' $_FileRead = FileRead ( $_FilePath ) $_NewText = _RemoveBetweenBrackets ( $_FileRead, 1 ) ConsoleWrite ( "!->-- $_NewText : " & $_NewText & @Crlf ) $_file = FileOpen ( $_FilePath, 2 ) FileWrite ( $_file, $_NewText ) FileClose ( $_file ) Func _RemoveBetweenBrackets ( $_Stringg, $_Option=1 ) ; 1 [ ], 2 ( ), 3 { }, 4 < >, 5 ‹ ›, 6 « » Local $_BracketsArray[13] = [12, '[' ,']' ,'(' ,')' ,'{', '}', '<', '>', '‹', '›', '«', '»'] Local $_chr1 = $_BracketsArray[$_Option*2-1], $_chr2 = $_BracketsArray[$_Option*2] $_StringBetweenArray = _StringBetween ( $_Stringg, $_chr1, $_chr2 ) If Not @error Then For $_S = 0 To UBound ( $_StringBetweenArray ) -1 $_StringInStr1 = StringInStr ( $_Stringg, $_chr1 & $_StringBetweenArray[$_S] & $_chr2 ) -1 $_StringInStr2 = StringLen ( $_StringBetweenArray[$_S] ) + 2 $_Stringg = StringLeft ( $_Stringg, $_StringInStr1 ) & StringRight ( $_Stringg, StringLen ( $_Stringg ) - $_StringInStr1-$_StringInStr2 ) Next Else Return $_Stringg EndIf Return StringStripWS ( $_Stringg, 7 ) EndFunc ;==> _RemoveBetweenBrackets ( ) It remove all occurences between brackets. Hey thx it works good but it is writing everything successively. e.g. [abc]abc [def]def [ghi]ghi ________solution abcdefghi but i want it underneath abc def ghi thx brN Link to comment Share on other sites More sharing options...
wakillon Posted August 5, 2011 Share Posted August 5, 2011 With a text file containing this[abc]abc[def]def[ghi]ghifunction return this :abcdefghiand not abcdefghi ! #include <String.au3> $_FilePath = 'C:\text.txt' $_FileRead = FileRead ( $_FilePath ) $_NewText = _RemoveBetweenBrackets ( $_FileRead, 1 ) ConsoleWrite ( "!->-- $_NewText : " & $_NewText & @Crlf ) $_file = FileOpen ( $_FilePath, 2 ) FileWrite ( $_file, $_NewText ) FileClose ( $_file ) Run ( 'notepad ' & $_FilePath ) Func _RemoveBetweenBrackets ( $_Stringg, $_Option=1 ) ; 1 [ ], 2 ( ), 3 { }, 4 < >, 5 ‹ ›, 6 « » Local $_BracketsArray[13] = [12, '[' ,']' ,'(' ,')' ,'{', '}', '<', '>', '‹', '›', '«', '»'] Local $_chr1 = $_BracketsArray[$_Option*2-1], $_chr2 = $_BracketsArray[$_Option*2] $_StringBetweenArray = _StringBetween ( $_Stringg, $_chr1, $_chr2 ) If Not @error Then For $_S = 0 To UBound ( $_StringBetweenArray ) -1 $_StringInStr1 = StringInStr ( $_Stringg, $_chr1 & $_StringBetweenArray[$_S] & $_chr2 ) -1 $_StringInStr2 = StringLen ( $_StringBetweenArray[$_S] ) + 2 $_Stringg = StringLeft ( $_Stringg, $_StringInStr1 ) & StringRight ( $_Stringg, StringLen ( $_Stringg ) - $_StringInStr1-$_StringInStr2 ) Next Else Return $_Stringg EndIf Return StringStripWS ( $_Stringg, 7 ) EndFunc ;==> _RemoveBetweenBrackets ( ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
brNwsH Posted August 5, 2011 Author Share Posted August 5, 2011 yeah the function is returning right but in my txt file everything is writtin successively so far brN Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now