Grasshopper

algorithmic modeling for Rhino

I want to extract a text fragment in the string, but the fragment is at the end of the string, and I don't know the string length.

Therefor, I'd like to count from the end and not the start of the string.

I tried using negative indexes, which works with a list, but it is not supported, apparently.

I found this workaround, but... yuck !

Cheers,

Views: 1607

Replies to This Discussion

How about these solutions:

Attachments:

Hi David,

Thanks !

"SplitWithSpaces" only works if there is indeed a space before the string I want to grab, but in "LengthExpression", the use of "Text Length" saves me a component, yay ! :)

Allowing negative values for the index would blend with the general logic, and it even might trigger a chain of events which would fix the left turn signal on my van.

Cheers,

Yeah it probably should work with negative and super-positive indices. I'll have to write my own substring algorithm in that case, but I guess that's what I'm getting paid for...

In that case, you might also want to add a "Contains" equivalent.

It took me a while to realize I couldn't use the text components to do that, and needed an expression.

Whatever you get paid is probably not in proportion with the money made by various businessed and schools around the world with Grasshopper, and that's not even considering the intrinsic value of this tool.

It made me fall in love again with math and geometry ; most importantly it got my rusty old brain firing neurones anew.

Thank you so much David.

"match text" can be used as a contains if you just set your search pattern to be *x* where x is what you want to test for in the other string. 

Ha! Indeed. Thanks Andrew.

The usual Zen style of the component's help box didn't quite help me here. 

What's a RegEx pattern, by the way  ?

I've got a few very basic VB components that may be of use... They work similar to what you would expect in excel Formula.

And I've added a Regex one since you mention it which Returns everything until the end of line.

Attached...

Attachments:

A regex_mid one as well..

Attachments:

RegEx stands for REGular EXpressions. It's a highly advanced way to specify textual pattern matching. In fact it is so advanced that I consider it to be utterly useless. It's just too bloody complicated and the only times I manage to use some regex pattern is if I find one online someone already made.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service