Apr-29-2019, 11:39 AM
(This post was last modified: Apr-29-2019, 11:40 AM by ichabod801.)
Let's start with:
Then we have:
Finally we have:
So altogether,
clientNo = ClientNumber.split("ClientNo", 1)That takes the string ClientNumber, and splits it everywhere there is the sub-string 'ClientNo', but only does it once (because of the final one). So if ClientNumber is '123 ClientNo 456 ClientNo 789', the result will be ['123', '456 ClientNo 789']. Note that the result is a list.
Then we have:
clientNo = ClientNumber.split("ClientNo", 1)[1]This indexes the list we got from split. Since Python is 0-indexed, the index 1 refers to the second item in the list. In the above example this would give us '456 ClientNo 789'.
Finally we have:
clientNo = ClientNumber.split("ClientNo", 1)[1][0:50]The [0:50] slices the string we got from the [1]. Especially for slices, it is helpful to think of the indexes as existing between the characters of the string, like this:
Output:characters: 4 5 6 C l i e n t ...
indexes: 0 1 2 3 4 5 6 7 8 9 10 ...
So we can see that [0:5] will get '456 C', the first 5 characters. Therefore [0:50] will get the first 50 characters. Note that 0 is the default first index in a slice, so [0:50] is often written as [:50].So altogether,
clientNo = ClientNumber.split("ClientNo", 1)[1][0:50]
gets the first 50 characters of text after the first instance of 'ClientNo'.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures