Jump to content

Need help removing last charcter in an array


rfedun
 Share

Recommended Posts

Hi, I'm new to autoit and I just need some help removing a pipe character at the end of my output for my function. Essentially I need a pipe character at the end of each day of the week except Sunday. If you guys could help me here, I would really appreciate it.

Local $days = StringSplit("Sunday,Monday,Tuesday,Wedneday,Thursday,Frday,Saturday", ",")
;$days[1] contains "Sun" ... $days[7] contains "Sat"


Local $text = "This\nline\ncontains\nC-style breaks."
Local $array = StringSplit($text, '\n', 1)

 


Local $sRecieved = "doc no.:"
Local $sPipe = "|"
For $i = 1 to $days[0]
   $sRecieved = $sRecieved & " " & $days[$i] & $sPipe
   $sRecieved = StringLeft($sRecieved, StringReplace($sPipe, $days - 1, " "))
  ; ConsoleWrite($sRecieved & StringLen($sRecieved) + $days[$i+1] + 1 & @CRLF)
   If $i < $days[0]  Then 
      If StringLen($sRecieved) < 20 and StringLen($sRecieved) + StringLen($days[$i+1]) + 1 > 20 Then  ; If Len($sLink) < 2047 and Len($sLink) + Len($aDocuments) + 1 > 2047 Then 
         MsgBox(0, "Days character length", $sRecieved)
         $sRecieved = "doc no.:"
         ; _ArrayDisplay($days)
      EndIf
   Else
      MsgBox(0, "Days character length", $sRecieved)
   EndIf
Next 
 

 

Link to comment
Share on other sites

Didn't really understand what your output should look like as the code above returned nothing for me, you could use a ternary operator to create the string, for example:

#include <Array.au3>
Local $aDays = StringSplit("Sunday,Monday,Tuesday,Wedneday,Thursday,Frday,Saturday", ",")
Local $sRecieved = "doc no.:"
Local $sPipe = "|"
For $i = 1 to $aDays[0]
    $sRecieved &= $i = 1 ? " " & $aDays[$i] : " " & $aDays[$i] & $sPipe
    ConsoleWrite($sRecieved & " - " & StringLen($sRecieved) & @CRLF)
    If StringLen($sRecieved) < 20 and StringLen($sRecieved) + (StringLen($aDays[$i]) + 1) > 20 Then MsgBox(0, "Days character length", $sRecieved)
    If $i = $aDays[0] Then MsgBox(0, "Days character length", $sRecieved)
Next

 

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...