Our files have the following name "J12345-01-001.
I want to split the name so it returns the value after the second -
Can anybody help with a simple code.
I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so
this then causes errors.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
@Anonymous wrote:
Our files have the following name "J12345-01-001.
I want to split the name so it returns the value after the second -
Can anybody help with a simple code.
I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so
this then causes errors.
Sounds like you should be using the "Strings.Right" method
A string containing a specified number of characters from the right side of a string.
Dim testString As String = "J12345-00001-002" ' Returns "002". Dim subString As String = Right(testString, 3)
Hi @Anonymous
I typically use the Split function for something like this. Here is an example that splits the string using the dashes
sMyString = "12345-01-001" 'split the string into an array using the dash sMyArray = sMyString.Split("-") 'use the members of the array in a message box MsgBox("the first bit is this: " & vbLf & sMyArray (0) ) MsgBox("the middle bit is this: " & vbLf & sMyArray (1) ) MsgBox("the last bit is this: " & vbLf & sMyArray (2) )
Here's another example using a backslash as the split characther, and it shows how to use UBound to find the upper bounds of the array, which in the case of a file path will always be the file name:
sMyString = "C:\TEMP\Test\11111-01\11-111.ipt" 'split the string into an array using the dash sMyArray = sMyString.Split("\") 'use the members of the array in a message box MsgBox("the first bit is this: " & vbLf & sMyArray(0) ) MsgBox("the next bit is this: " & vbLf & sMyArray(1) ) MsgBox("the next bit after that is this: " & vbLf & sMyArray(2)) 'get the upper bounds of the array 'in this case it would be the file name i = UBound(sMyArray) MsgBox("the file name is this: " & vbLf & sMyArray(i)) 'change the string sMyString = "C:\TEMP\Test\111-1111\11111-01\111-1111\11111-01\11-111.ipt" sMyArray = sMyString.Split("\") 'get the upper bounds of the array 'in this case it would be the file name i = UBound(sMyArray) MsgBox("Length of path changed, but we can still find the file name easily: " & vbLf & sMyArray(i))
Just a reminder, programming questions of this type are generally placed on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I'll as the forum moderators to move this thread to that forum for you.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Can't find what you're looking for? Ask the community or share your knowledge.