ahmeddzcom Posted January 15, 2023 Posted January 15, 2023 (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, 2023 by ahmeddzcom
Danp2 Posted January 15, 2023 Posted January 15, 2023 Take a look at the _ArrayTrim function. ahmeddzcom and SOLVE-SMART 2 Latest Webdriver UDF Release Webdriver Wiki FAQs
Solution Musashi Posted January 15, 2023 Solution Posted January 15, 2023 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) pixelsearch, SOLVE-SMART and ahmeddzcom 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."
SOLVE-SMART Posted January 15, 2023 Posted January 15, 2023 (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, 2023 by SOLVE-SMART ahmeddzcom 1 ==> AutoIt related: 🔗 GitHub, 🔗 Discord Server Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon)
SOLVE-SMART Posted January 15, 2023 Posted January 15, 2023 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 ==> AutoIt related: 🔗 GitHub, 🔗 Discord Server Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon)
ahmeddzcom Posted January 15, 2023 Author Posted January 15, 2023 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
OJBakker Posted January 15, 2023 Posted January 15, 2023 See: _ArrayTrim online doc The option is to remove left OR right.
ahmeddzcom Posted January 15, 2023 Author Posted January 15, 2023 (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, 2023 by ahmeddzcom
OJBakker Posted January 15, 2023 Posted January 15, 2023 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
Musashi Posted January 15, 2023 Posted January 15, 2023 (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, 2023 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."
ahmeddzcom Posted January 15, 2023 Author Posted January 15, 2023 @Musashi yes i did , because i need trim lines not have the same number of characters
Musashi Posted January 15, 2023 Posted January 15, 2023 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."
Malkey Posted January 16, 2023 Posted January 16, 2023 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
ahmeddzcom Posted January 17, 2023 Author Posted January 17, 2023 (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, 2023 by ahmeddzcom
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