Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic split a string

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
4076 Views, 6 Replies

Ilogic split a string

Goodday,


I am searching for a way to split strings. Where:

Dim Separators() As Char = {";"} 

Doesnt seem to work at my code.

 

As you see in the code the separator is-> ;

for example, if the string is 1;2, it must be separated into 1 and 2 given to 2 parameters,

so spot1 -> "1" and spot2 -> "2"

This also applies to, for example, 4;6;13 in 4, 6 and 13 given to 3 parameters, etc.

 

I hope i can find the solution im looking for over here!

Kind Regards,

Thomas

6 REPLIES 6
Message 2 of 7
Sergio.D.Suárez
in reply to: Anonymous

 

Hi Thomas, this should be the snippet you use to split the string.

 

Dim Separators() As Char = {";"} 
Sentence = "1;2;3;4;5"
Words = Sentence.Split(Separators)
i = 0
For Each wrd In Words
MessageBox.Show("Word Index #" & i & " = " & Words(i))
i=i+1
Next

and for your specific case you could use

 

Dim Separators() As Char = {";"} 
Sentence = "10;20;3;4;5"
Words = Sentence.Split(Separators)

spot1 = Words(0)
spot2 = Words(1)

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

 

Where spot1 and spot2 are your user parameters to redefine.
I hope this helps solve your problem. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 7
Anonymous
in reply to: Sergio.D.Suárez

Thank you Sergio!

 

It worked did work, i changed it a bit to this;

Dim Separators() As Char = {";"} 
Sentence = StringParameter
If Sentence = "1;1" Then
Words = Sentence.Split(Separators)
spot1 = Words(0)
spot2 = Words(1)
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
Else If Sentence = "1;5;7" Then
Words = Sentence.Split(Separators)
spot1 = Words(0)
spot2 = Words(1)
spot3 = Words(2)
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
End If 
InventorVb.DocumentUpdate()
Message 4 of 7
Sergio.D.Suárez
in reply to: Anonymous

I'm glad you solved it. The fragment is just an update

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

 so I usually place it at the end of the code, it is not necessary to repeat it many times, you can eliminate those that are higher and leave only the last one. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 7
LSKELLY
in reply to: Sergio.D.Suárez

Hi Sergio

 

Thanks. This code has worked well for me but I find only one frustrating quirk with it. If I try to split on line breaks it splits it so that each split segment is preceded by a line break rather than deleting the splitting character as it did with the semi-colons. The modified code below will illustrate the problem:

 

Dim Separators() As Char = {";",vbCrLf} Sentence = "1" & vbCrLf & "2" & vbCrLf & "3" & vbCrLf & "4" & vbCrLf & "5"
Words = Sentence.Split(Separators)
i = 0
For Each wrd In Words
MessageBox.Show("Word Index #" & i & " = " & Words(i))
i=i+1
Next

 

Do you have any idea how to elegantly work around this or prevent it?

Message 6 of 7
Curtis_Waguespack
in reply to: LSKELLY

Hi @LSKELLY 

 

I think this should work for you:

 

Sentence = "1" & vbCrLf & "2" & vbCrLf & "3" & vbCrLf & "4" & vbCrLf & "5"
Words = Sentence.Split(vbCrLf)

For Each wrd In Words
	'strip out carraige returns & linefeeds
	wrd = wrd.Replace(vbCr, "").Replace(vbLf, "")
	MessageBox.Show("Word Index #" & i & " = " & wrd)
Next

 

 

Also just as a reminder, you can search and ask programming questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

(I've asked the moderators that this topic be moved to that forum to help in the future)

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 7 of 7
LSKELLY
in reply to: Curtis_Waguespack

Excellent! Thanks Curtis!

 

Kicking myself right now.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report