Jump to content

Long String of Text into Several Short Strings


Go to solution Solved by Melba23,

Recommended Posts

Hello! I have searched all over the web for a similar question but I couldn't find the answer... here's an example of what I'm trying to accomplish:

Global $A1 = ('"C:\Desktop\File1.jpg" ') & ('"C:\Desktop\File2.jpg" ') ; <--- I want to split these so that they are on separate lines

; I want it to look something like this:

Global $A1 =
"C:\Desktop\File1.jpg"
"C:\Desktop\File2.jpg"

The thing is, I have several different texts that need to have quotes. So, to bypass this, I have to type everything in brackets, add the "&" symbol, and on top of that, I have to type it all on 1 line... That seems like a very long path for something so simple. Is there any easier way of doing this? Maybe even removing the need for brackets and dual quotes?

Thank you!

Link to comment
Share on other sites

Global $sA1 = ('"C:\Desktop\File1.jpg" ') & ('"C:\Desktop\File2.jpg" ') ; <--- I want to split these so that they are on separate lines

$aA1 = stringsplit($sA1 , " " , 2)

msgbox(0, '' , $aA1[0] & @CRLF & $aA1[1])

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hello "boththose:) 

I considered using the String Split function, however, File1 and File2 were just shortened examples... my real files have very long path names and by splitting the string as you mentioned, it doesn't really change the fact that I must first type:

"$sA1 = Global $sA1 = ('"C:\Desktop\File1.jpg" ') & ('"C:\Desktop\File2.jpg" ')"

I understand what you did, but that isn't exactly what I wanted to accomplish... what I'm trying to do is send these words (file paths) to a website in order to upload images. So, I need each variable to equal different file paths as strings with quotes. So by doing this:

Global $A1 = ('"C:\Desktop\CAT.JPG" ') & ('"C:\Desktop\DOG.JPG" ')  ; & so on.....
; $A2 = and so on...

You can see, I may have lots and lots of file paths to include and by typing all of this into one long variable string would be very inconvenient (especially if I need to change them every now and then). That's why typing them on separate lines would be very helpful to read and change them accordingly.

I considered doing the method below, however, it keeps returning an error:

Global $A1

Func $A1()
Send(""C:\Desktop\CAT.JPG" ")
Send(""C:\Desktop\DOG.JPG" ")
EndFunc

Do
Send($A1) ; <--- types "C:\Desktop\CAT.JPG" and "C:\Desktop\DOG.JPG"
Send ("{ENTER}") ; <--- Hits enter to upload
$counter = $counter + 1
Until $counter = 3 ; repeats "x" amount of times

What am I doing wrong?

 

I'm a quick learner, I just need to be pointed in the right direction by someone advanced because I am new to programming. So, thank you for helping me "boththose"  :) Your knowledge will be used wisely.

Edited by PROGRAMPROGRAM
Link to comment
Share on other sites

I'm not fully understanding what you are wanting here, but I notice you have double quotes inside double quotes, which doesn't work. You need to either have doubles inside singles or singles inside doubles.

i.e. Send('"C:DesktopCAT.JPG" ')

Your first line would be better like this -

Global $A1 = '"C:\Desktop\File1.jpg"|"C:\Desktop\File2.jpg"|"C:\Desktop\File3.jpg"'

Which you can then do a StringSplit on the pipe character.

We need to see more of your code, to better understand .... where you are getting your files (entries) from and where are they going, etc.

You should be asking this post in General Help & Support, not here, and you will find more people are likely to notice and help there.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Basically, I'm trying to upload files - and to upload them, I need to make AutoIt type the file destination. Sometimes I need to upload several files per variable. So, I can go the long way:

Global $A1 = ('"C:\Desktop\CAT.JPG" ') & ('"C:\Desktop\DOG.JPG" ') & ('"C:\Desktop\TURTLE.JPG" ') & ('"C:\Desktop\COW.JPG" ') ; and so on..... 

I need to change the file names and destinations every now and then, so it won't be easy to find and change a particular file, as you can see, it would be a very long string all on one line. I basically want to make it like paragraphs of text. Something short and easy to read like this:

Global $A1 = 
('"C:\Desktop\CAT.JPG" ')
('"C:\Desktop\DOG.JPG" ')
('"C:\Desktop\TURTLE.JPG" ')
('"C:\Desktop\COW.JPG" ')

But that doesn't work.

Here's what my script looks like so far:

Global $counter = 0
Global $AMOUNT = 2

Global $A1 = ('"C:\Desktop\something (1).jpg" ') & ('"C:\Desktop\something (2).jpg" ') & ('"C:\Desktop\something (3).jpg" ') & ('"C:\Desktop\something (4).jpg" ')
Global $A2 = ('"C:\Desktop\somethingelse (0).jpg" ') & ('"C:\Desktop\somethingelse (1).jpg" ') & ('"C:\Desktop\somethingelse (2).jpg" ') & ('"C:\Desktop\somethingelse (3).jpg" ') & ('"C:\Desktop\somethingelse (4).jpg" ')
; It goes on and on with $A3, 4, 5, and 6
; As you can see, this becomes very long and messy with all the text on one line...

; then, I do this:
Do
; CREATES "$A + LOOP NUMBER"
Local $A = "A" & $counter+1
; TURNS $A INTO VARIABLE RATHER THAN TEXT AND TYPES THE TEXT IN THE VARIABLE LOCATED IN $A1 (2, 3, AND SO ON...)
send(eval(eval("A")))
; CLICKS "ENTER" ONCE FILES ARE SELECTED
Send ("{ENTER}")
; COUNTS LOOP BY +1
$counter = $counter + 1
; LOOPS UNTIL VARIABLE "$AMOUNT"
Until $counter = $AMOUNT

; The end...

What I'm asking is very simple, I just don't know how to make it work. Please help.

Thank you

Edited by PROGRAMPROGRAM
Link to comment
Share on other sites

  • Moderators
  • Solution

PROGRAMPROGRAM,

Use the line extension operator:

Global $A1 = _
('"C:\Desktop\CAT.JPG" ') & _
('"C:\Desktop\DOG.JPG" ') & _ 
('"C:\Desktop\TURTLE.JPG" ') & _
('"C:\Desktop\COW.JPG" ')
Now all that is the same line.

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

 

Link to comment
Share on other sites

The & _ works I used to use that for long strings.

$msg = "this is " & _
"my really " & _
"really really " & _
"long string"
MsgBox(0, "", $msg)

The way I started to do it of late that feels a bit more organized to me is something like.

$msg2 = "this is "
$msg2 &= "my really "
$msg2 &= "really really "
$msg2 &= "long string"
MsgBox(0, "", $msg2)
Link to comment
Share on other sites

  • Moderators

ViciousXUSMC,

The syntax in that second example is really useful when the total string gets very long and can bump into line length limits (4096 if I remember correctly) - otherwise I tend to stick with the line extension character. But thanks for pointing out the option.

M23

Edited by Melba23
Typnig

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

 

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