Left( [TEXTSTRING], Len( [TEXTSTRING] ) [position] )
That is an error with the expression format itself. Double check your field names and that you are using Python instead of VB.
ERROR 000539: SyntaxError: EOL while scanning string literal (<expression>, line 1)
Can you post the full error you are receiving so we can see what has been passed that causes the error? It should look something like this.Executing: CalculateField blocks TEST_LABEL "!SOURCEID![: !TEXT_INTS! ]" PYTHON_9.3 # Start Time: Tue Mar 04 12:48:53 2014 ERROR 000539: Error running expression: u"FA07908426251"[: u"2014" ] Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: slice indices must be integers or None or have an __index__ method Failed to execute (CalculateField). Failed at Tue Mar 04 12:48:53 2014 (Elapsed Time: 0.04 seconds) You can find it under the 'Results' tab
Executing: CalculateField blocks TEST_LABEL "!SOURCEID![: !TEXT_INTS! ]" PYTHON_9.3 # Start Time: Tue Mar 04 12:48:53 2014 ERROR 000539: Error running expression: u"FA07908426251"[: u"2014" ] Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: slice indices must be integers or None or have an __index__ method Failed to execute (CalculateField). Failed at Tue Mar 04 12:48:53 2014 (Elapsed Time: 0.04 seconds)
Messages Executing: CalculateField OWNERSHIP_TEXT Label "!TEXTSTRING![:int (!postion!)]" PYTHON_9.3 # Start Time: Tue Mar 04 16:55:32 2014 ERROR 000539: SyntaxError: EOL while scanning string literal (<expression>, line 1) Failed to execute (CalculateField). Failed at Tue Mar 04 16:55:32 2014 (Elapsed Time: 0.10 seconds)
Are you trying to calculate a field or create a label?
Could you post a sample of your table you are trying to calculate and the applicable field types?
If you are just looking to get everything before the word "out" in a text string, how about: !TEXTSTRING!.split("out")[0].strip()
!TEXTSTRING!.split("out")[0].strip()
Do you mean splitting it up by white space and finding where the word 'out' is within a string? If so, you could get the position with something like this: >>> a = 'this is out at pos 2' >>> b = 'out at pos 0' >>> c = 'pos 3 is out' >>> def findIndex(string, word): return string.split().index(word) >>> for test in [a, b, c]: print findIndex(test, 'out') 2 0 3 I don't know much VB so I'm not sure what you're doing once you have the index?EDIT: Matt's answer is waaaay better than mine.
>>> a = 'this is out at pos 2' >>> b = 'out at pos 0' >>> c = 'pos 3 is out' >>> def findIndex(string, word): return string.split().index(word) >>> for test in [a, b, c]: print findIndex(test, 'out') 2 0 3
If using field calculator try this.!TEXTSTRING![:int(!position!)]int() may or may not be required depending on field type of "position"
!TEXTSTRING![:int(!position!)]
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.