Sign in to follow this  
Followers 0
gil900

StringSplit Anything except one thing ?

15 posts in this topic

$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?

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 add

And 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

the code Should return 3

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

What you gave me is great.

I am a little change the code to use only what it returns.

Thank you!

Share this post


Link to post
Share on other sites

#8 ·  Posted (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)
EndFunc

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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by gil900

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by gil900

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0