Jump to content

Stringleft and Array


Go to solution Solved by Musashi,

Recommended Posts

  • Solution

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)

 

Musashi-C64.png

"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 comment
Share on other sites

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 by SOLVE-SMART

Stay innovative!

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)

Link to comment
Share on other sites

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

Stay innovative!

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)

Link to comment
Share on other sites

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 comment
Share on other sites

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 by ahmeddzcom
Link to comment
Share on other sites

@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 by Musashi
Typo

Musashi-C64.png

"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 comment
Share on other sites

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

Musashi-C64.png

"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 comment
Share on other sites

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")

 

Link to comment
Share on other sites

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 by ahmeddzcom
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...