ahmeddzcom 5 Posted January 15 Share Posted January 15 (edited) Hello Can Stringleft a array ? #include <array.au3> Local $aArray = [1111, 2222222222, 333333333333333333333] _ArrayDisplay($aArray) $SLeft = StringLeft($aArray,3) _ArrayDisplay($SLeft) ;~ this not work of course :) so the result is ; 111 , 222 , 333 tnx. Edited January 15 by ahmeddzcom Link to post Share on other sites
Danp2 1,362 Posted January 15 Share Posted January 15 Take a look at the _ArrayTrim function. SOLVE-SMART and ahmeddzcom 2 WebDriver UDF [GH&S] Latest version Wiki FAQs Link to post Share on other sites
Solution Musashi 715 Posted January 15 Solution Share Posted January 15 Or : #include <array.au3> Local $aArray = [111111111, 2222222222, 3333333333] _ArrayDisplay($aArray) For $i = 0 To UBound ($aArray) -1 Step 1 $aArray[$i] = StringLeft($aArray[$i] , 3) Next _ArrayDisplay($aArray) ahmeddzcom, pixelsearch and SOLVE-SMART 2 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to post Share on other sites
SOLVE-SMART 110 Posted January 15 Share Posted January 15 (edited) Hi @ahmeddzcom, like @Musashi already posted (only few minutes before I could write this here down 😅😞 #include-once #include <Array.au3> Local $aArray = [1111111111, 2222222222, 3333333333] _ArrayDisplay($aArray, 'Before') Local Const $aNewArray = _StringLeftIn1dArray($aArray, 3) _ArrayDisplay($aNewArray, 'After') Func _StringLeftIn1dArray($aArray, $iCount) For $i = 0 To Ubound($aArray) - 1 Step 1 $aArray[$i] = StringLeft($aArray[$i], $iCount) Next Return $aArray EndFunc [...] anyways, I guess the suggestion of @Danp2 might be the best - it's already provided by AutoIt, so no need for a custom function. Best regards Sven Edited January 15 by SOLVE-SMART ahmeddzcom 1 Stay innovative! Spoiler 🌍 Au3Forums 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔍 Forum search 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to post Share on other sites
SOLVE-SMART 110 Posted January 15 Share Posted January 15 I am a bit confused @ahmeddzcom, because the solution should be @Danp2s post in my opinion. Of course at the end it's up to you what you prefer (and also sorry to @Musashi - nothing personaly 😇). But for other people it would be more helpful to know about what is already provided by AutoIt (Danp2 post) and this should be the solution. Best regards Sven ahmeddzcom 1 Stay innovative! Spoiler 🌍 Au3Forums 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔍 Forum search 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to post Share on other sites
ahmeddzcom 5 Posted January 15 Author Share Posted January 15 2 minutes ago, SOLVE-SMART said: I am a bit confused @ahmeddzcom, because the solution should be @Danp2s post in my opinion. Of course at the end it's up to you what you prefer (and also sorry to @Musashi - nothing personaly 😇). But for other people it would be more helpful to know about what is already provided by AutoIt (Danp2 post) and this should be the solution. Best regards Sven i can't use _ArrayTrim . Because _ArrayTrim remove only (remove left and rigth) . i need get three characters so i think _ArrayTrim not working for me 😃 tnx @SOLVE-SMART Link to post Share on other sites
OJBakker 18 Posted January 15 Share Posted January 15 See: _ArrayTrim online doc The option is to remove left OR right. Link to post Share on other sites
ahmeddzcom 5 Posted January 15 Author Share Posted January 15 (edited) 4 minutes ago, OJBakker said: See: _ArrayTrim online doc The option is to remove left OR right. Hi @OJBakker i think _ArrayTrim not working with this code : #include <array.au3> Local $aArray = [1111, 2222222222, 333333333333333333333333] _ArrayDisplay($aArray) For $i = 0 To UBound ($aArray) -1 Step 1 $aArray[$i] = StringLeft($aArray[$i] , 3) Next _ArrayDisplay($aArray) Edited January 15 by ahmeddzcom Link to post Share on other sites
OJBakker 18 Posted January 15 Share Posted January 15 You are right. _ArrayTrim() won't work. You want as parameter: Number of characters to remove. _ArrayTrim() wants as parameter: Number of characters to trim. ahmeddzcom 1 Link to post Share on other sites
Musashi 715 Posted January 15 Share Posted January 15 (edited) @ahmeddzcom : You will now encounter another problem: In your original question, the elements of the array looked like this : Local $aArray = [111111111, 2222222222, 3333333333] An hour ago you edited your starting post, and now it contains the following values : Local $aArray = [1111, 2222222222, 333333333333333333333333] The integer value 333333333333333333333333 is outside the allowed limits, i.e. : -2^63 largest negative value , 2^63-1 largest positive value (= 9223372036854775807) . As a result, the element $sArray is displayed as 9223372036854775807 not as 333333333333333333333333 Edited January 15 by Musashi Typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to post Share on other sites
ahmeddzcom 5 Posted January 15 Author Share Posted January 15 @Musashi yes i did , because i need trim lines not have the same number of characters Link to post Share on other sites
Musashi 715 Posted January 15 Share Posted January 15 11 minutes ago, ahmeddzcom said: ... because i need trim lines not have the same number of characters I got that . The problem is the size of the third value. If you need to work with values that exceed the above limits, then it is worth taking a look at the bignum-udf ahmeddzcom 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to post Share on other sites
Malkey 243 Posted January 16 Share Posted January 16 Here are two one-liners that will return StringLeft() and StringRight() of all items in a 1D or 2D array. #include <array.au3> ; 1D Aarray Local $aArray[] = ["02", 1234, 23456789, "3456733333333333333333333"] ; Or, 2D Array ;Local $aArray[][] = [["02", 1234, 23456789, "3456733333333333333333333"],["ab", "cdefg","hijklmnop"]] _ArrayDisplay($aArray) $aArray1 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "([^!\v]{3}).[^!\v]*", "\1"), "!") ; _ArrayAllItemsStringLeft _ArrayDisplay($aArray1, "Left") $aArray2 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "[^!\v]*([^!\v]{3})", "\1"), "!") ; _ArrayAllItemsStringRight _ArrayDisplay($aArray2, "Right") ahmeddzcom 1 Link to post Share on other sites
ahmeddzcom 5 Posted January 17 Author Share Posted January 17 (edited) On 1/16/2023 at 1:01 AM, Malkey said: Here are two one-liners that will return StringLeft() and StringRight() of all items in a 1D or 2D array. #include <array.au3> ; 1D Aarray Local $aArray[] = ["02", 1234, 23456789, "3456733333333333333333333"] ; Or, 2D Array ;Local $aArray[][] = [["02", 1234, 23456789, "3456733333333333333333333"],["ab", "cdefg","hijklmnop"]] _ArrayDisplay($aArray) $aArray1 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "([^!\v]{3}).[^!\v]*", "\1"), "!") ; _ArrayAllItemsStringLeft _ArrayDisplay($aArray1, "Left") $aArray2 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "[^!\v]*([^!\v]{3})", "\1"), "!") ; _ArrayAllItemsStringRight _ArrayDisplay($aArray2, "Right") thanx @Malkey exactly what I needed 😃 Edited January 17 by ahmeddzcom Link to post Share on other sites
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