Parsing Semicolon-Separated Numbers from Multiline Input

Started by amosfuegel, July 24, 2025, 06:55:53 PM

Previous topic - Next topic

amosfuegel

Hi, I want to prompt the user to enter a list of numbers. Each line should contain 4 numbers, separated by semicolons (;), and ending with @CR. There will be 250 or more lines in total.

I've used AskTextBox to get the input and successfully split the input string into an array using line breaks (@LF), resulting in an array with 250 elements, which works fine.

The problem is, I don't know how to parse each line of the array into its 4 individual numbers. For example, if a line looks like "123;456;789;012", how do I extract each of those numbers into separate variables or elements?

Here's what I have so far:


; Get input from user
userInput = AskTextBox("Enter your number list:", "Input Required", "", 0, 0)

; Split the input into lines
linesArray = Arrayize(userInput, @LF)
totalLines = ArrInfo(linesArray, 1)

; This doesn't work as expected
For i = 0 To totalLines - 1
    currentLine = linesArray(1)  ; ERROR HERE
    ParseData(currentLine)
Next

How can I properly process 250 lines, where each line has 4 numbers separated by ;, and store them in a 2D array or otherwise access each individual value? Thank you

td

Your array syntax is not correct for the line:

currentLine = linesArray(1)  ; ERROR HERE

It should be currentLine = linesArray[i]

Also, ParseData will not break out semicolon separated values. Try Arrayize with a quoted semicolon as the function's second parameter.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

SMF spam blocked by CleanTalk