Select to view content in your preferred language

String from index position

2117
18
03-03-2014 12:18 PM
NoahHuntington
Deactivated User
Trying to calculate field using all the leftmost characters of [TEXTSTRING] up to the first occurrence of "out" in [TEXTSTRING] whose position has been calculated and placed in [POSITION] field.  The following is  vbscript but I'm sure there is an easy python solution to this. The script should help clarify...

[position] = first occurrence of "out" in [TEXTSTRING]

label:
Left( [TEXTSTRING], Len( [TEXTSTRING] ) [position] )


I hope this make sense?
Tags (2)
0 Kudos
18 Replies
NoahHuntington
Deactivated User
Are you trying to calculate a field or create a label?


Ultimately label.  In doing so was attempting to create new label field? Open to label expression too!
0 Kudos
MathewCoyle
Honored Contributor
If neither of the posted samples worked for you something odd is going on with your data or how you are executing the calculator. Are you sure you are enabling Python instead of VB? What errors or messages do you get?
0 Kudos
NoahHuntington
Deactivated User
Matt,

position is a long, new label field and textstring are string fields...

using:
!TEXTSTRING![:int( !position!)]

received:
error 000539: exceptions.TypeError: cannot concatenate 'str' and 'int' objects.
0 Kudos
MathewCoyle
Honored Contributor
Is that your entire expression? Can you take a screenshot of your field calculator window with the code you execute that returns that error? Also can you post the entire error message? And what version of ArcGIS are you using? Something isn't adding up here.
0 Kudos
NoahHuntington
Deactivated User
[ATTACH=CONFIG]31928[/ATTACH]

This is what I'm attempting?
0 Kudos
MathewCoyle
Honored Contributor
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
0 Kudos
NoahHuntington
Deactivated User
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


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)
0 Kudos
MathewCoyle
Honored Contributor
ERROR 000539: SyntaxError: EOL while scanning string literal (<expression>, line 1)


That is an error with the expression format itself. Double check your field names and that you are using Python instead of VB.
0 Kudos
NoahHuntington
Deactivated User
That is an error with the expression format itself. Double check your field names and that you are using Python instead of VB.


If I ran yesterday according to the picture provided at 11:18 where do you suppose I went wrong? FYI: [postion] although misspelled is the actual field name...
0 Kudos