Grasshopper

algorithmic modeling for Rhino

I feel like I had seen a discussion like this before, but I cannot find it now.

I have a string that is "(0:1:0)(1:0:1)(0:0:1)". How can I extract only one part of it at a time. SO, I want the 1st 0 as one output, the 1st 1 as one output, the 2nd 0 as another output... and so on.

I thought there was an expression in the function component, but I could not find it on the expression list.

Views: 1686

Replies to This Discussion

I think you'll have to use VB or C#. I didn't wrap the Split() function in the expression language, since it returns an array of values, which is difficult to deal with in an Expression.

You can use one of the String.Split() overloads in the DotNET Framework if you decide to use VB or C#.

Note that splitting often works on an array of chars, rather than whole Strings. This is sometimes confusing and usually it means it's best to perform a few replacement operations prior to splitting:

myString = myString.Replace(")(", "|")
myString = myString.Replace("(", String.Empty)
myString = myString.Replace(")", String.Empty)

Dim parts As String() = myString.Split("|"c)
Dim numbers As New List(Of Integer)

For Each part As String in parts
Dim sub_parts As String() = part.Split(":")
For Each sub_part As String in sub_parts
numbers.Add(Integer.Parse(sub_part))
Next
Next


--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks for the reply David.
I will try this out.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service