Jump to content

How to convert String to Array without any delimiters?


Recommended Posts

I'd like to take a string like|this and turn it to a 1 key array such as:

Array[1] (
      [0] => like|this

There seem to be 2 functions (one internal and the other is an UDF) that are meant for this, but both of which require to supply a delimiter for this to always work.
Now of course I can fake a delimiter that I don't expect to exist (like @CRLF).
Alternatively, I can use a middleman variable, but it seems like a waste.
Is there a more normal (i.e. delimiter and middleman free) way to do it?

$foobar = "like|this", $foobar2 = $foobar, $foobar3 = $foobar

$foobar = StringSplit($foobar, @CRLF, 3)) ; the delimiter here is a mandatory field
; or
include <Array.a3u>
$foobar2 = _ArrayFromString($foobar2, @CRLF)) ; the delimiter here is optional but the default "|" will break my string
; or
local $foobar_temp[1] = [$foobar3] ; making up a whole new parameter just for this
$foobar3 = $foobar_temp


Edited by LWC
Added comment
Link to comment
Share on other sites

1 hour ago, LWC said:

But that's exactly one of my aforementioned interim solutions. See above what I wrote about it.

And what do you want more? You have the desired result by direct assignation, however, Subz has a point in questioning why such a construct is even needed.


When the words fail... music speaks.

Link to comment
Share on other sites

And what's the point of filling a 1-element array with a string you already have?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

4 hours ago, LWC said:

middleman free) way to do it?

The answer is no. You can make yourself believe that there's nothing delimiting but something has to. Otherwise how is the system to know that in "foobar" there is "foo" and "bar" and not just "foobar" or "fo" "ob" "ar". Old databases would declare that a field is X char long and that's a way to delimit fields if that is simpler for your code.

None the less there is no way around it that I can think of. Even this HTML page you are reading, separates the header from the body with a double @CRLF as a delimiter.

Now my question is why. Why do you envision that as a solution ?. What is the problem ?

Edit: opps. Anyway, you're looking for Opt("GUIDataSeparatorChar", Chr(1)) ; The default character is '|'.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.

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

  • Create New...