开发者

split string error in a compiled VB.NET class

I'm having some trouble compiling some VB code I wrote to split a string based on a set of predefined delimeters (comma, semicolon, colon, etc). I have successfully written some code that can be loaded inside a custom VB component (I place this code inside a VB.NET component in a plug-in called Grasshopper) and everything works fine. For instance, let's say my incoming string is "123,456". When I feed this string into the VB code I wrote, I get a new list where the first value is "123" and the second value is "456".

However, I have been trying to compile this code into it's own class so I can load it inside Grasshopper separately from the standard VB component. When I try to compile this code, it isn't separating the string into a new list with two values. Instead, I get a message that says "System.开发者_Python百科String []". Do you guys see anything wrong in my compile code? You can find an screenshot image of my problem at the following link: click to see image

This is the VB code for the compiled class:

Public Class SplitString
Inherits GH_Component
Public Sub New()
    MyBase.New("Split String", "Split", "Splits a string based on delimeters", "FireFly", "Serial")
End Sub
Public Overrides ReadOnly Property ComponentGuid() As System.Guid
    Get
        Return New Guid("3205caae-03a8-409d-8778-6b0f8971df52")
    End Get
End Property
Protected Overrides ReadOnly Property Internal_Icon_24x24() As System.Drawing.Bitmap
    Get
        Return My.Resources.icon_splitstring
    End Get
End Property
Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)
    pManager.Register_StringParam("String", "S", "Incoming string separated by a delimeter like a comma, semi-colon, colon, or forward slash", False)
End Sub
Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)
    pManager.Register_StringParam("Tokenized Output", "O", "Tokenized Output")
End Sub
Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
    Dim myString As String
    DA.GetData(0, myString)

    myString = myString.Replace(",", "|")
    myString = myString.Replace(":", "|")
    myString = myString.Replace(";", "|")
    myString = myString.Replace("/", "|")
    myString = myString.Replace(")(", "|")
    myString = myString.Replace("(", String.Empty)
    myString = myString.Replace(")", String.Empty)

    Dim parts As String() = myString.Split("|"c)
    DA.SetData(0, parts)

End Sub

End Class

This is the custom VB code I created inside Grasshopper:

Private Sub RunScript(ByVal myString As String, ByRef A As Object)
myString = myString.Replace(",", "|")
myString = myString.Replace(":", "|")
myString = myString.Replace(";", "|")
myString = myString.Replace("/", "|")
myString = myString.Replace(")(", "|")
myString = myString.Replace("(", String.Empty)
myString = myString.Replace(")", String.Empty)

Dim parts As String() = myString.Split("|"c)
A = parts

End Sub

'

'

End Class


Well, knowing nothing about Grasshopper, I'm just going to have to guess...

System.String [] is what .NET would print if you called ToString() on a string array. So, I'm gonna guess that you've given Grasshopper an array where it wants a single string.

So, with a little further guessing, how 'bout we try:

Dim parts As String() = myString.Split("|"c) 
For I = 0 to parts.Length -1
    DA.SetData(I, parts[I]) 


Well, I tried the code snippet you suggested... but it didn't quite work. I think the problem in the original code is that I'm trying to send a list of values (ie. parts) to a single output node. So, when I use DA.SetData(0,parts) I'm writing a list of values to the first output node of my compiled component. However, I think the problem is that the component doesn't know that parts is a list. In the example I gave before, if my incoming string is "123,456" then my result split list should have two values (123 and 456). I don't think I have declared parts to be a list. Do you have any ideas on how to do this? Again, if you click on the link in the original email (while using Internet Explorer... I'm not sure why Firefox isn't opening it) you should see a screenshot of the setup in the Grasshopper plugin which should help give you an idea of what's going on. Thanks again for your help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜