SlimShady Posted January 10, 2005 Posted January 10, 2005 StringReplace says 8 here: $Str = "aaaaaaaa" StringReplace($Str, "a", "") ;$num = @error $num = @extended MsgBox(64, "Debug", "$num:" & @CRLF & $num)
Developers Jos Posted January 10, 2005 Developers Posted January 10, 2005 StringReplace says 8 here:$Str = "aaaaaaaa" StringReplace($Str, "a", "") ;$num = @error $num = @extended MsgBox(64, "Debug", "$num:" & @CRLF & $num)<{POST_SNAPBACK}>Think they are talking about "aa" SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nova Posted January 10, 2005 Author Posted January 10, 2005 (edited) I dont see a way of editing my current script to allow for this problem without changing the entire logic to using StringReplace. And that brings about the problem of not being able to find the location in the entire text file where the string was located. Plus I like the method im using at the moment becasue I tought of it myself and therfore it makes more sense to me that other methods posted so far, even thought it dosent work as well So if I change to using StringReplace I can no longer have this format | Occurance = 1 Location = x | Suggestions and ideas welcome Edited January 10, 2005 by Nova
killaz219 Posted January 10, 2005 Posted January 10, 2005 (edited) Fine Lar I updated my script so it returns the right amount. Func SearchString($string, $text) Local $i, $timespresent, $char Do $char = Chr(Random(32, 255)) Until StringInStr($string, $char) = 0 For $i = 1 To StringLen($string) Local $check $check = StringMid($string, $i, StringLen($text)) If $check == $text Then $string = StringReplace($string, $check, $char, 1) $timespresent = $timespresent + 1 FileWrite("test.txt", $i & " ") EndIf Next Return $timespresent EndFunc Edited January 10, 2005 by killaz219
Nova Posted January 10, 2005 Author Posted January 10, 2005 (edited) Edit: Nope found horrible problems give me an hour or so Edited January 10, 2005 by Nova
Nova Posted January 10, 2005 Author Posted January 10, 2005 (edited) Depending on your needs both answers are right... it should be an "option" flag to the function.Lar.a "unique occurance" flag<{POST_SNAPBACK}>So ideally both StringInStr and StringReplace should have a "unique occurance" opt flag ?That sure would solve alot of problems for me at the moment because im stubbern and dont want to change my script to using another method.Would it be easy for a dev to impliment these function opt flags into autoits code ? Edited January 10, 2005 by Nova
SlimShady Posted January 10, 2005 Posted January 10, 2005 (edited) I have updated my code with the option Larry suggested. $Str = "aaaaaaaa" $num = CountSubs($Str, "aa", 0) MsgBox(64, "Debug", "$num:" & @CRLF & $num) $num = CountSubs($Str, "aa", 1) MsgBox(64, "Debug", "$num:" & @CRLF & $num) Func CountSubs($Text, $Subs, $Opt = 0) Local $num Local $Match $num = 1 If $Opt = 0 Then While StringInStr($Text, $Subs, 0, $num) $num = $num + 1 WEnd Else While 1 $Match = StringInStr($Text, $Subs) If NOT $Match Then ExitLoop $num = $num + 1 $Text = StringTrimLeft($Text, ($Match - 1) + StringLen($Subs)) WEnd EndIf Return $num - 1 EndFunc Edit: - Made it a little smaller - added examples for both options Edited January 10, 2005 by SlimShady
Nova Posted January 12, 2005 Author Posted January 12, 2005 (edited) Ok I finally found some time to fix up my string finder script. It now has a find unique string occurance option, it also still records the correct position of the string, as far as I can tell no other script posted so far records the true position of the unique strings. This is the last time ill post this updated script in the support section, all further update posts will be in scripts and scraps, unless I actually need support that is Please test this if you have a spare min expandcollapse popup#include "GUIConstants.au3" Opt("GUIOnEventMode",1) $Main_Gui = GUICreate("Novasoft - Word finder", 600, 600) $Group1_files = GUICtrlCreateGroup ("Files", 10, 145, 580, 100) $Group2_options = GUICtrlCreateGroup ("Search options", 10, 255, 580, 100) $Group3_results = GUICtrlCreateGroup ("Results", 10, 360, 580, 200) $Input1_files = GUICtrlCreateInput ("", 150, 165, 300, 25, $ES_READONLY) $Input2_files = GUICtrlCreateInput ("", 150, 205, 300, 25) GUICtrlSetState ( $Input1_files , $GUI_DISABLE ) GUICtrlSetState ( $Input2_files , $GUI_DISABLE ) $Lable1_files = GUICtrlCreateLabel (" Load (Text .txt file) ",30, 169, 100) $Lable2_files = GUICtrlCreateLabel (" Search for (Text) ",30, 209, 100) $Lable3_results = GUICtrlCreateLabel ("Occurance = 0" ,100, 380, 500) $Lable3_results_font = GUICtrlSetFont ($Lable3_results, 9, 600, -1, "Comic Sans MS") $Checkbox1_options = GUICtrlCreateCheckbox ("Case sensitive", 50, 300, 120, 20) $Checkbox2_options = GUICtrlCreateCheckbox ("Is unique", 200, 300, 120, 20) $Edit1_results = GUICtrlCreateEdit ("", 30,405,240,140,$ES_AUTOVSCROLL+$WS_VSCROLL + $WS_HSCROLL) $Edit2_results = GUICtrlCreateEdit ("", 325,405,240,140,$ES_AUTOVSCROLL+$WS_VSCROLL + $WS_HSCROLL) $Button1 = GUICtrlCreateButton ( "Browse", 455, 165, 60, 25) GUICtrlSetOnEvent($Button1, "Browse_Pressed") $Button2 = GUICtrlCreateButton ( "Search", 455, 205, 60, 25) GUICtrlSetOnEvent($Button2, "Search_Pressed") GUICtrlSetState ( $Button2 , $GUI_DISABLE ) GUISetState () GuiSetOnEvent($GUI_EVENT_CLOSE, "quit") Func quit() Exit EndFunc Func Browse_Pressed() $sltd = FileOpenDialog ( "Select file to search", @HomeDrive, "Text files (*.txt)" , 1 + 2) If @error Then Else GUICtrlSetData ( $Input1_files, $sltd) GUICtrlSetState ( $Button2 , $GUI_ENABLE) GUICtrlSetState ( $Input2_files , $GUI_ENABLE ) GUICtrlSetState ( $Input2_files , $GUI_FOCUS ) EndIf EndFunc Func Search_Pressed() Local $occ Local $is_unique = 1 Local $not_unique = 2 $state = GUICtrlRead ( $Checkbox1_options ) $occ = GUICtrlRead ( $Checkbox2_options ) If $state = 4 Then $case = 0 Else $case = 1 EndIf If $occ = 4 Then $occ = $not_unique Else $occ = $is_unique EndIf If $occ = $is_unique Then GUICtrlSetData($Lable3_results, "Occurance = 0" ) GUICtrlSetData($Edit1_results, "") GUICtrlSetData($Edit2_results, "") sleep(250) $sltd = GUICtrlRead ( $Input1_files ) $string = FileRead($sltd, FileGetSize($sltd)) $text = GUICtrlRead ( $Input2_files ) $textlen = StringLen ( $text ) $chara = " " If @error Then Else $location = StringInStr($string, $text, $case, 1) If $location = 0 Then MsgBox(0, "Search result:", "No such string exists") Else GUICtrlSetData($Edit2_results, $string, 1) If $textlen = 1 Then $blanks = " " Else Do $blanks = $blanks & $chara $value = StringLen($blanks) Until $value = $textlen EndIf $i = 1 $location = StringInStr($string, $text, $case) $string = StringReplace ($string, $text, $blanks , 1 , $case) GUICtrlSetData($Lable3_results, "Occurance = " & $i ) GUICtrlSetData($Edit1_results, @CRLF, 1) GUICtrlSetData($Edit1_results, " Occurance = " & $i & " Location = " & $location, 1) Do $i = $i +1 $location = StringInStr($string, $text, $case) $string = StringReplace ($string, $text, $blanks , 1 , $case) If $location = 0 Then ExitLoop Else Sleep(250) GUICtrlSetData($Lable3_results, "Occurance = " & $i ) GUICtrlSetData($Edit1_results, @CRLF, 1) GUICtrlSetData($Edit1_results, " Occurance = " & $i & " Location = " & $location, 1) EndIf Until $location = 0 EndIf EndIf Else GUICtrlSetData($Lable3_results, "Occurance = 0" ) GUICtrlSetData($Edit1_results, "") GUICtrlSetData($Edit2_results, "") sleep(250) $sltd = GUICtrlRead ( $Input1_files ) $string = FileRead($sltd, FileGetSize($sltd)) $text = GUICtrlRead ( $Input2_files ) If @error Then Else $location = StringInStr($string, $text, $case, 1) If $location = 0 Then MsgBox(0, "Search result:", "No such string exists") Else $i = 1 $location = StringInStr($string, $text, $case, $i) GUICtrlSetData($Lable3_results, "Occurance = " & $i ) GUICtrlSetData($Edit1_results, @CRLF, 1) GUICtrlSetData($Edit1_results, " Occurance = " & $i & " Location = " & $location, 1) GUICtrlSetData($Edit2_results, $string, 1) Do $i = $i +1 $location = StringInStr($string, $text, $case, $i) If $location = 0 Then ExitLoop Else Sleep(250) GUICtrlSetData($Lable3_results, "Occurance = " & $i ) GUICtrlSetData($Edit1_results, @CRLF, 1) GUICtrlSetData($Edit1_results, " Occurance = " & $i & " Location = " & $location, 1) EndIf Until $location = 0 EndIf EndIf EndIf EndFunc While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Edited January 12, 2005 by Nova
Nova Posted January 12, 2005 Author Posted January 12, 2005 Is it possible to set the colour of text in an edit control ? I was under the influence that you can not set colour to text in this way. But then again JdeB's scite editor sets tons of different colours to keywords, wasnt scite written in autoit ?
MHz Posted January 12, 2005 Posted January 12, 2005 @NovaScite originates from here. JdeB customizes it for Autoit use. Any Autoit code used, is in the onboard tools, like Scite-Config etc only.
Developers Jos Posted January 12, 2005 Developers Posted January 12, 2005 (edited) Is it possible to set the colour of text in an edit control ?I was under the influence that you can not set colour to text in this way.But then again JdeB's scite editor sets tons of different colours to keywords, wasnt scite written in autoit ?<{POST_SNAPBACK}>I only wrote the portion of code in SciTE that does the Syntax HighLighting/Coloring and the Folding for AutoIt3 files.But I am not sure what you are looking for ..... Edited January 12, 2005 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nova Posted January 12, 2005 Author Posted January 12, 2005 (edited) O rite I though JdeB was the author of scite and that he wrote it in au3.Woops my mistake.But I am not sure what you are looking for .....@JdeB My above script displays the textfile selected in full in the second edit control the one on the rightI would like to highlight the word that was seached for in this edit control.For example say this is the contents of a text fileHello I am a text fileand a search has been done for the string "am" then I would like my edit control to look like this.Hello I am a text fileI do not see any current functions that will allow you to edit text in a edit control to make it stand out....... say by change its colour or making it bold.Because this highlight text/ keywords is a key feature in scite and I though scite was written in au3, I figured there was a way to do it. Edited January 12, 2005 by Nova
Helge Posted January 12, 2005 Posted January 12, 2005 O rite I though JdeB was the author of scite and that he wrote it in au3.<{POST_SNAPBACK}>Scite written in AutoIt v3 ?Eeeehmm..
Nova Posted January 12, 2005 Author Posted January 12, 2005 (edited) Black then white are all I see in my infancy.Red and yellow then came to be, reaching out to me.Lets me see.As below, so above and beyond, I imagineDrawn beyond the lines of reason.Push the envelope. Watch it bend.@Helge Tool rock Lateralus is one of my fav songs@house (That means you )I know GUICtrlSetFont could set my desired text to bold..... but it cannot set the colour of the text. Edited January 12, 2005 by Nova
Nova Posted January 12, 2005 Author Posted January 12, 2005 Now that I think of it what I really need is a StringColour function Could such a function be coded ? or is there some limitation to strings that im not aware of ? Something like StringColour ( "string", start [, count [, colour ]]) Would it be worth my time sub mitting a request to the idealab ? I mean would anybody else have use for such a function ?
Helge Posted January 12, 2005 Posted January 12, 2005 (edited) @Helge Tool rock Lateralus is one of my fav songs@house (That means you )<{POST_SNAPBACK}>Awsome ! Tool is definitive my favourite band !Actually I'm wearing a Tool-tshirt at the moment, and I also havea mp3-disc with all the Tool-albums (plus some other bands) in the cd-tray right now!!No kidding !! -(I'm supposed to sing)Edit : Ooh, I forgot..what did you mean with "@house(That means you ) Edited January 12, 2005 by Helge
Nova Posted January 12, 2005 Author Posted January 12, 2005 (edited) @house "means im talking to everyone whos reading this" so when I said (that means you) I was talking to everyone who read it. Local $macro1 = @house Local $macro2 = @everyone $macro1 = $macro2 @house = @everyone Im was listening to Aenima when I first read your sig Edit: Anyone got any advice on my StringColour idea or should I just post in the lab with a request and a million "plz plz plz's" Edited January 12, 2005 by Nova
Helge Posted January 12, 2005 Posted January 12, 2005 (edited) Ok, I see !I'm currently listening to Salival....aah.. Therapy for the mind !I simple love that album !Aenima you say...well...As a patriot I have to say : Aenima < Ænima Edited January 12, 2005 by Helge
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