How can I push a comma delimited string into an array?

I am working through the Tutorial document and have run into something that puzzles me. I have input the following code from the tutorial:

//push comma delimited string from an array
Var tags() As String
Var combinedTags As String
tags.AddRow(“Movies”)
tags.AddRow(“Comedy”)
tags.AddRow(“90s”)
combinedTags = tags.FromArray(",")
// combinedTags is now “Movies,Comedy,90s”

And Im getting these errors:

Window1.PushButton1.Action, line 44
Type “String()” has no member named “FromArray”
combinedTags = tags.FromArray(",")
Window1.PushButton1.Action, line 44
Type mismatch error. Expected String, but got Int32
combinedTags = tags.FromArray(",")

Blockquote

Can someone please explain why?

Thanks in advance for any light you can shed.
Del Thompson

Just use

combinedTags = String.FromArray(tags, ",")

Just a bad language design causing confusion to those expecting combinedTags = tags.Join(",")

3 Likes

Here’s an example you can try out:

// Let's create a new array that will hold some fruit.
var basket() as String

// Add three fruits to the array.
basket.add("apples")
basket.add("bananas")
basket.add("coconuts")

// Now, let's create a string that contains all of the fruit in the basket.

var shoppingList as String
shoppingList = String.FromArray(basket, ", ")

MessageBox(shoppingList)

Hope this helps.

Amen to that … :man_facepalming:

3 Likes

Thank you Byron, your example code worked for me. Are you saying that addrow doesn’t work with character string arrays in xojo? Or is it that the fromarray function doesn’t
work with string arrays that have been loaded with addrow? should I just use add anytime I’m building a string array?

Del

AddRow for Arrays is deprecated and now is just .Add

Edit: What tutorial are you using? Is that on the web? I guess it needs to be updated.

1 Like

Hi Del,

About a year ago, Xojo renamed AddRow() to simply Add(). Personally, I think it’s a nice improvement, as it makes it easier for developers to remember. :wink:

The fromArray() method takes each item (in the array) and adds it to a string. Take a look at the following code:

var names() as String

names.add("Corey")
names.add("Stephanie")
names.add("Joel")

// Let's put all of the names together in a string!
var totalNames as String
totalNames = String.FromArray(names, "-")

// The totalNames string will now contain the following:
// "Corey-Stephanie-Joel"

MessageBox(totalNames)

In case you’re curious, the String.FromArray() has two parts. The first is String, while the second is a method called FromArray(). String is what is called a “class”. A class is very much like a toolbox, as it contain many useful tools (such as FromArray) inside that you can use. In order to use one of the tools, I have to specify which toolbox that I want to use (the “String” class) and which tool (the “FromArray” method) inside that I want to use. This is why you see it as: String.FromArray()

Hope this helps.

2 Likes

In summary, the example in the tutorial is wrong.

Thank you Byron. Yes, your explanation is very helpful. After 40 years of working in the IT field(now retired!), I can fully appreciate the difficulty of keeping documentation up to date for ever changing software. :slight_smile: Most of my time in the field was spent with procedural(COBOL,PL1) languages and what they called 4th generation languages(FOCUS,SPS) and query language(SQL). Recently I decided to challenge myself and learn something about object oriented development. XOJO appealed to me because of its cross platform capability. Never having worked in the C language terms like CLASS are unfamiliar to me. I would guess it equivalent somewhat to a subroutine in COBOL or PL/1. Anyway, I explain all of this because although my questions may seem inane, I’m really trying to understand the terminology and relate it to what I already know. Your explanation was right on! I’m enjoying my journey into XOJO so far and am quite amazed and thankful at how helpful the user community is.

Del

1 Like

I’m not sure where I found it on the web but the title of the book is:

Introduction to programming with Xojo
A textbook
RHINE,LEFEBRE

Acknowledgements
Special thanks go out to Brad Rhine who wrote the original
versions of this book with help from Geoff Perlman (CEO of Xojo,
Inc).
We’d also like to acknowledge the Xojo community. We often hear
your stories about how Xojo made it easy for you to learn
programming or build an app or start your own business. You
have made Xojo possible for over 20 years.

This book is in PDF format, I downloaded it.

I prefer complete books for future references as apposed to the on-line web based approach that
XOJO provides with the IDE. I searched until I found this but now realize it might be out of date.

1 Like

Just found the URL in the book:

Del is correct.

A single search for .AddRow in the 4th Edition returns a bunch of found entries (with API2 code around).

If I have a comma delimited String like “1,2,3,4,5,6” and I want it to be an array I could do

var a() as string
var b as string = “1,2,3,4,5,6”
a=b.split(",")

and I would get a as an array containing the comma separated string. In my view the simplest way. So you would need to combine this with your solution

The change from AddRow (you can still use it without problems) to Add was after the book release.

Prior to all this madness, it was “append”, which was a perfectly-suited keyword, but unfortunately Xojo decided its users are too uneducated to know what “append” means.

2 Likes

Thank you - I got an update that I needed LOL