Jump to content
Sign in to follow this  
BlazerV60

Storing a "|" inside an array

Recommended Posts

BlazerV60

Hello everyone,

I was trying to store this string into my array: "Hamsters | Cute"

But after I store it, I used _ArrayDIsplay and it showed "Hamster" being on one row and "Cute" being on the row after it.

So it looks like the "|" symbol acts as a row seperator in an array.

My question is: Is there a way for my array to display "Hamsters | Cute" in 1 row ?

Thanks,

Brian

Share this post


Link to post
Share on other sites
ghost11996

Hi BlazerV60

Can you post some of your script ?

Maybe try check autoit wiki http://www.autoitscript.com/wiki/Arrays

If im not wrong then you are using this :

Local $iMax
 
Local $data = "Element 1|Element 2|Element 3"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, "|")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

Try change "|" to "," and check stringsplit function : https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm

Local $iMax
 
Local $data = "Hamster | Cute,Array2 | Array2"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, ",")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf
Edited by ghost11996

[color=rgb(255,0,0);]C[/color][color=rgb(255,140,0);]a[/color][color=rgb(255,215,0);]n[/color] [color=rgb(255,255,0);]i[/color] [color=rgb(175,238,238);]e[/color][color=rgb(0,255,255);]a[/color][color=rgb(64,224,208);]t[/color] [color=rgb(0,0,205);]S[/color][color=rgb(0,0,255);]i[/color][color=rgb(0,0,128);]g[/color][color=rgb(75,0,130);]n[/color][color=rgb(128,0,128);]at[/color][color=rgb(238,130,238);]u[/color][color=rgb(221,160,221);]r[/color][color=rgb(230,230,250);]e[/color] [color=rgb(0,255,0);]?[/color] :ermm: [color=rgb(0,255,0);]Project: Mini Youtube BETA[/color]

Share this post


Link to post
Share on other sites
BlazerV60

 

Hi BlazerV60

Can you post some of your script ?

Maybe try check autoit wiki http://www.autoitscript.com/wiki/Arrays

If im not wrong then you are using this :

Local $iMax
 
Local $data = "Element 1|Element 2|Element 3"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, "|")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

Try change "|" to "," and check stringsplit function : https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm

Local $iMax
 
Local $data = "Hamster | Cute,Array2 | Array2"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, ",")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

 Hi ghost

,

Thanks for responding! For certain reasons, I need the separator to be "|" and not a comma or any other symbol.

Here is what my code looks like:

#include <Array.au3>
#include <MsgBoxConstants.au3>

$Ham1 = "Hamster"
$Ham2 = "Cute"

Local $aArray_Base[2] = ["Org item 1", "Org item 2"]

_ArrayAdd($aArray_Base, $Ham1&"|"&$Ham2)
_ArrayDisplay($aArray_Base, "1D - Base array")

Share this post


Link to post
Share on other sites
guinness

Did you read the help file for _ArrayAdd()? Change the $sDelim_Item to something other than |.

Ticket closed!

  • Like 1

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
czardas

If you avoid using _ArrayAdd() then you should not encounter such problems. It is best if you know the size of the array in advance, then you can simply assign values to the array elements as and when needed.

;

#include <Array.au3>

Local $aArray[3] ; 3 elements are needed

$aArray[0] = "Hamster"
$aArray[1] = "Cute"
$aArray[2] = $aArray[0] & "|" & $aArray[1]

_ArrayDisplay($aArray)

;

Also take a look at ReDim in the help file (for resizing arrays).

Edited by czardas

Share this post


Link to post
Share on other sites
Melba23

BlazerV60,

See my posts >here and later in the same thread for more explanation. :)

M23

  • Like 1

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
czardas

The changes to _ArrayAdd() certainly make the function more flexible, which I see as a definite improvement. :)

Share this post


Link to post
Share on other sites
Melba23

czardas,

Thanks for that. :thumbsup:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
mikell

Using the OP's code in post #3 and assuming that the expected output is a 1D array - and using _ArrayAdd and its really nice improvement  :)

#include <Array.au3>

$Ham1 = "Hamster"
$Ham2 = "Cute"

Local $aArray_Base[2] = ["Org item 1", "Org item 2"]

_ArrayAdd($aArray_Base, $Ham1&"|"&$Ham2, 0, ";")
_ArrayDisplay($aArray_Base, "1D - Base array")

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  

  • Similar Content

    • lattey
      By lattey
      hi,
      i have checkboxes and each checkbox that checked, i put in array. 
      now, im stuck on how to loop the checked array and store in in one variable. what i can do now, is only write the result into a text file. 
      below is the code:
      #include <GUIConstantsEx.au3> ;~ #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> Global $Count = 3 Global $CheckBoxP[$Count] Global $step[$Count] global $array1[1] Global $ExitResult $hGUI = GUICreate("Summary Steps", 500, 400) GUISetFont(12, 400, "Tahoma") GUICtrlCreateLabel( "Please Select the Summary Steps for Script Check", 70, 20) GUISetFont(10, 400, "Tahoma") Global $array_Pstep[3] = ["fix2","fix1","fix3"] global $step[3] = ["2","3","4"] $Spacing = 50 For $i = 0 To UBound($array_Pstep) - 1 $CheckBoxP[$i] = GUICtrlCreateCheckbox($array_Pstep[$i], 80, $Spacing + (20 * $i), 65, 17) Next $submit = GUICtrlCreateButton("Submit",180, 280, 80, 30) $exit = GUICtrlCreateButton("Exit",180, 320, 80, 30) GUISetState() While 1 $Msg = GUIGetMsg() Select case $Msg=$submit For $i = 0 To $Count - 1 If GUICtrlRead($CheckBoxP[$i]) = $GUI_CHECKED Then _ArrayAdd($array1, $step[$i]) EndIf Next Global $logfilerray = @WorkingDir & "\checkedlist.txt" FileDelete ($logfilerray) Global $readlogfile = FileOpen($logfilerray,1) for $a = 1 to UBound($array1) - 1 ;~ $var=$array1[$a] FileWriteLine($readlogfile,$array1[$a]) Next FileClose($readlogfile) Exit case $Msg=$exit $ExitResult = MsgBox(1,"Summary Step", "Continue to Exit ?") if $ExitResult = 1 Then ;ok Exit EndIf Exit EndSelect WEnd  
    • omicron
      By omicron
      How do you perform a nested loop function with a multidimensional array from 2 lists.
      for i in list1
      (open file) extract variable
          while open for i in list 2
          (open file2) extract variable
       
      var1 + var2 = (search term)

      The list sizes will more than likely consist of different lengths.
       
      What is the best approach to accomplishing this method?
             
    • omicron
      By omicron
      Hello!

      I am working on a function that I am just getting lost on. The goal is a multiple nested loop.

      Here are the steps:
      Contents of file1.txt::
      [topic] var1=Name var2=OtherName var3=SomeotheName Contents of file2.txt::
      [subTopic] top=sub1 top2=sub2 top3=sub3 The Shell I am working from::
      #include <file.au3> $file = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) msgbox(0,'','the line ' & $i & ' is ' & $line) Next FileClose($file) Understanding however that the "msgbox" needs to then become a variable. in example the following::
      $file = "c:\yourfile.txt" FileOpen($file, 0) While true( prog.exe is running && "WinName" is open) do For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ;Open File to log "current location of file 1" FileWriteLine ("filename", $i & ' is ' & $line) var = $line Next $file2 = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ; OpenFile to log "Current location of file 2" FileWriteLine ("filename", $i & ' is ' & $line) Next FileClose($file2) FileClose($file) The goal in written form is the following ::

      While in "OpenWindow"
          read from file 1 starting at line 1 until end of file.
         file 1 is a list of names to be searched.
         With $line selected, add this element to the element in file 2.
       
      The search of a variables in list 1 and list 2 differ on the amount of posts that day. (This is not a web based platform, it is a game) I need to search 2 names and take a screenshot of the out put. The sizes of the names list depend on the activity of names at the time of search.
      This loop continues until all the names from both lists have been searched. Mostly in the format of::
      File1= item
      File2= Vendor
       
      Item + Vendor  ( Capture screen, scroll) -- Not sure how to detect if I need to scroll)
       
      Thank you for your help and support!
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
×