Guest Posted August 19, 2012 Share Posted August 19, 2012 $test = StringSplit($text, "?")in the "?" (delimiters - One or more characters to use as delimiters (case sensitive).) i want to Write something that is every thing except one thing i do not want to remove in the split.How to do it? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 19, 2012 Moderators Share Posted August 19, 2012 gil900, Sounds like a RegEx might do the trick. Can you give us an example of the string you want to split and what character you do not want to act as a delimiter? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 I have a beautiful example for line: af_+s jsd ad test1 cax >> { [ =0 test1 cxxw test2 &60 8{] ~@3 43( - test2 I want to delete everything except from test1 or something else that i will add.. in the loop, It will return $Value[$i]. Each $Value[$i] are the same thing. But for example, if in the line there is three times of "test1" Then in the final phase, $i will return 3. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 19, 2012 Moderators Share Posted August 19, 2012 gil900, This does it for me: #include <Array.au3> $sString = "af_+s jsd ad test1 cax >> { [ =0 test1 cxxw test2 &60 8{] ~@3 43( - test2" $aRet = StringRegExp($sString, "test1", 3) _ArrayDisplay($aRet, "Total = " & UBound($aRet)) or something else that i will addAnd what might that be? It should be easy enough to add to the SRE pattern. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 thanks i will chack your code.I just want to fix a few things I've said.I do not want to delete anything in this line. I just need basic code that will return me the number of the "test1" (how many times it is in the line.)For example, if I have in the line example 10 times of test1, then the code will return me the number 10.The example I gave is not correct enough.This is the new example:nacergeadtest1cueafetest1kfaaxcutest1vjjaegoogle.comavndthe code Should return 3 Link to comment Share on other sites More sharing options...
BrewManNH Posted August 19, 2012 Share Posted August 19, 2012 You could do something simple like $array = StringSplit(<your string>, "test1") and then $array[0] would tell you how many times it found "test1". If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 What you gave me is great. I am a little change the code to use only what it returns. Thank you! Link to comment Share on other sites More sharing options...
Bowmore Posted August 19, 2012 Share Posted August 19, 2012 (edited) The code Melba23 gave you basically gave you what you were looking for. I've rearranged that into a little generic function for you._StringCountInString(ByRef $sData, $sFind)Func _StringCountInString(ByRef $sData, $sFind) Local $aRet = StringRegExp($sData, $sFind, 3) Return UBound($aRet) EndFuncExample of how to use it$sString = "af_+s jsd ad test1 cax >> { [ =0 test1 cxxw test2 &60 8{] ~@3 43( - test2" $iCount = _StringCountInString($sString, "test1") MsgBox(0,"Count",$iCount) $iCount = _StringCountInString($sString, "test2") MsgBox(0,"Count",$iCount) $iCount = _StringCountInString($sString, "test") MsgBox(0,"Count",$iCount) Func _StringCountInString(ByRef $sData, $sFind) Local $aRet = StringRegExp($sData, $sFind, 3) Return UBound($aRet) EndFunc Edited August 19, 2012 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 19, 2012 Moderators Share Posted August 19, 2012 BrewManNH,Sorry to point it out, but your StringSplit code gives the number of instances plus 1. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted August 19, 2012 Share Posted August 19, 2012 Good point...didn't think it through all the way. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted August 19, 2012 Share Posted August 19, 2012 (edited) Thanks but I prefer what BrewManNH gave me. I'm not the kind of person who likes to use codes are completely ready. Because for me, it will take more time to adjust them to my code. And I hate doing things without understanding them. I'm afraid to depend too much on the forum. Edited August 19, 2012 by Guest Link to comment Share on other sites More sharing options...
Guest Posted August 21, 2012 Share Posted August 21, 2012 (edited) gil900, This does it for me: #include <Array.au3> $sString = "af_+s jsd ad test1 cax >> { [ =0 test1 cxxw test2 &60 8{] ~@3 43( - test2" $aRet = StringRegExp($sString, "test1", 3) _ArrayDisplay($aRet, "Total = " & UBound($aRet)) And what might that be? It should be easy enough to add to the SRE pattern. M23 OK Now I did another test. It turns out that it can not find a few cases. for example, if my line Contains - "test" and i Looking for "Test" so it didnt found Because the letter - T I looked in the Help file. I saw something with [:class:] but I could not understand how to use it. What to do? Edited August 21, 2012 by Guest Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 21, 2012 Moderators Share Posted August 21, 2012 gil900, If you look closer at the Help file you will see this: (?i) Case-insensitivity flag Then you can do this: #include <Array.au3> $sString = "af_+s jsd ad test1 cax >> { [ =0 Test1 cxxw test2 &60 8{] ~@3 43( - test2" $aRet = StringRegExp($sString, "(?i)test1", 3) _ArrayDisplay($aRet, "Total = " & UBound($aRet)) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Guest Posted August 21, 2012 Share Posted August 21, 2012 Thank you! I missed it because my English Link to comment Share on other sites More sharing options...
Spiff59 Posted August 21, 2012 Share Posted August 21, 2012 This yields the same result but appears to be a lot faster: #include <Array.au3> $sString = "af_+s jsd ad test1 cax >> { [ =0 Test1 cxxw test2 &60 8{] ~@3 43( - test1" ;-------------------------------------------------- $timer = TimerInit() For $x = 1 to 100000 $cnt = Count1() Next $timer = TimerDiff($timer) / 1000 MsgBox(0, Round($timer, 2), $cnt) ;-------------------------------------------------- $timer = TimerInit() For $x = 1 to 100000 $cnt = Count2() Next $timer = TimerDiff($timer) / 1000 MsgBox(0, Round($timer, 2), $cnt) ;-------------------------------------------------- Func Count1() $aRet = StringRegExp($sString, "(?i)test1", 3) Return UBound($aRet) EndFunc ;-------------------------------------------------- Func Count2() StringReplace($sString, "test1", "") Return @extended EndFunc 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