Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How to remove a special number of characters of a string, e.g. the last 7 characters? And how to join them as the first characters to the string of another field? Thank you for VBS and Python synthax help.

share|improve this question
    
What software do you use? ArcMap? Which version? –  Martin Apr 22 at 7:08
    
I'm using ArcMap 10.1 –  Shauna Apr 22 at 7:16
    
Welcome to GIS SE! Looking at your Question the only thing that ties it loosely to GIS is the inclusion of arcgis-10.1 and field-calculator tags. Even with these, such a Question which talks only about VBscript and Python would normally be closed as off topic for here and recommended for migration to StackOverflow. Consequently, please take care to ensure that Questions you ask here are always on topic for GIS SE. –  PolyGeo Apr 22 at 8:17
    
I thought stackexchange is the right board to get help with questions like mine. It is a problem quite refering to GIS. Do I have to shift it to another board? –  Shauna Apr 22 at 8:49
add comment

1 Answer 1

In python:

def function(string1, string2):
    return string1[-7:] + string2

Then use:

function(!field1_name! , !field2_name!)
share|improve this answer
    
I used this synthax and replaced field1_name and field2_name by my field names but it didn't work. Do I have to replace anything else? Shall I use both instructions in one step? –  Shauna Apr 22 at 8:02
    
What type of fields are field1 and field2? If you have there integer, you have to convert it to string before return it to your new field. Also check what type of field has your third column which should contains the result (it must be "text"). First instruction paste to "Pre-Logic script code", and second instruction to the textbox below. –  dmh126 Apr 22 at 8:08
    
I didn't know that I have to create a third column. Where do I have to put that third one in the python synthax? –  Shauna Apr 22 at 9:02
    
Simply, use field calculator on this column. You don't need to mention about it in python function. The returned value will be returned to this column. –  dmh126 Apr 22 at 9:07
    
I'm using field calculator exclusively. How does ArcMap know where to return the value? The execution failed --> error running expression: function(string1, string2) --> global name 'string' is not defined. –  Shauna Apr 22 at 10:24
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.