VB.Net Conversion To Python

VB.Net Conversion To Python

isocam
Collaborator Collaborator
379 Views
2 Replies
Message 1 of 3

VB.Net Conversion To Python

isocam
Collaborator
Collaborator

Can anybody help?

 

Purely as a test, can anybody please convert the following code from VB.Net to Python for me?

 

Dim TestString As String = "50 x 50 x 2.9 SHS x 800 Long - Mitred Both Ends"

 

LeftString = Strings.Left(TestString, 1 + InStrRev(TestString, "x"))

 

RightString = Strings.Right(TestString, (Strings.Len(TestString) - (InStrRev(TestString, "Long") - 2)))

 

MsgBox(LeftString + "7855" + RightString)

 

Many thanks in advance!

 

Kind Regards

 

Darren

0 Likes
380 Views
2 Replies
Replies (2)
Message 2 of 3

brkline
Observer
Observer

It can't be converted because you didn't define LeftString and RightString so the code to be converted isn't valid.

0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor

This should do it.

TestString = "50 x 50 x 2.9 SHS x 800 Long - Mitred Both Ends"
LeftString = TestString[:TestString.rfind('x') + 1]
RightString = TestString[TestString.rfind('Long'):]
print(f'{LeftString} 7855 {RightString}')
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes