XGamerGuide Posted May 3, 2021 Share Posted May 3, 2021 Hey, I want to use StringSplit with whole words, but unfortunately I couldn't find a way. I mean something like: $array = StringSplit("This is a test", "is") ; I would like to receive the following: ; $array[0] = 2 ; $array[1] = "This " ; $array[2] = " a test" Link to comment Share on other sites More sharing options...
TheXman Posted May 3, 2021 Share Posted May 3, 2021 (edited) 29 minutes ago, XGamerGuide said: I want to use StringSplit with whole words StringSplit is not the best way to do it but the example below does return your desired result: #include <Array.au3> $array = StringSplit("This is a test", " is ", $STR_ENTIRESPLIT) _ArrayDisplay($array) It's not the best way to do it because words can be delimited by more than just spaces. For example, this would not work correctly using the example above: "Red is: a color." or "It is, what it is." Edited May 3, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
XGamerGuide Posted May 3, 2021 Author Share Posted May 3, 2021 It works. thanks Link to comment Share on other sites More sharing options...
Nine Posted May 3, 2021 Share Posted May 3, 2021 Since your initial request was to keep the space before and after "is", you could use SRE like this : #include <Constants.au3> #include <Array.au3> Local $sString = "This is a test and this is a new test" Local $arr = StringRegExp($sString, "(.+?)(?|\bis\b|$)", 3) _ArrayDisplay($arr) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted May 3, 2021 Share Posted May 3, 2021 @XGamerGuide, when you said 2 hours ago, XGamerGuide said: I want to use StringSplit with whole words... did you mean more exactly, “I want to use StringSplit with a multi-character delimiter...” ? Code hard, but don’t hard code... 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