5

I have field with numbers in it (field type: double, number format: numeric) and I need to create a new field and put text in front of the numbers. I know that I need to add a new string field, but what is the proper expression to put into field calculator?

For example, if my number is 123, I want to change it to be abc123.

I'm using ArcMap 10.1

6
  • 1
    I see the problem you are having, it isn't behaving as it should.. Commented Aug 4, 2015 at 17:55
  • What software are you working with?
    – Barbarossa
    Commented Aug 4, 2015 at 17:59
  • Solved it for ArcGIS for Desktop 10, which I believe is what Katie is using. Commented Aug 4, 2015 at 18:11
  • Cameron - your answer was the only one that worked, but it looks like you deleted it. Can you post it again? Also, I'm having trouble repeating it because I'm not able to add fields with a field type of string anymore. It's not an option.
    – Katie
    Commented Aug 5, 2015 at 12:13
  • It is posted again. As for the new problem, try making another question so this one doesn't get too cluttered, I will keep my eyes peeled for it. Commented Aug 5, 2015 at 14:22

5 Answers 5

10

This will depend on what software you're using. Since you mentioned Field Calculator in your question, you are going to be using a programming language parser to convert values.

For Python (ArcMap, QGIS), you can use python's built in conversion functions. This page explains it fairly well and shows examples.

If you're using ArcMap and VBScript, there are a second set of functions you can use. They are explained here and provide examples, too.

Basically in either case, you are going to do a combination of the two fields while converting the one that needs it.

Python: stringField + str(numberField)

VBScript: stringField & CStr(numberField)

Warning: This isn't accounting for field value checking or anything that may throw a casting/conversion/type error.

Once you tell us which piece of software you're using, I can edit this answer with more detail and examples.

2
  • What field type should I be using? My layer is a feature class in a geodatabase so string isn't a field type option
    – Katie
    Commented Aug 5, 2015 at 12:08
  • @Katie, your fields should reflect what they are holding. If you have names of objects (comprised of letters) those should be stored in a text field, whereas if you are working with numbers (as values, not as tags) they should be stored in a numerical field such as short, long, double, float. Commented Aug 5, 2015 at 14:21
6

Here is the solution to your question in ArcMap 10.1 when using VB Script.

Your example for this will be: "abc" & [integer] within the expression box.

If you would like to have a space between your expression will be : "abc" & " " & [integer] (Note that there is a space between the middle parentheses).

From what Adam said: Using the Python parser will require type casting the integer to a string: "abc" + str(!integer!)

2
  • 2
    this is correct is using the VBScript parser. using the python parser will require type casting the integer to a string: "abc" + str(!integer!)
    – Adam
    Commented Aug 5, 2015 at 0:30
  • VB languages (without Option Strict set) are much more forgiving with implicit casting. It is a good habit to explicitly cast items so you can more readily jump around languages without seeing all the Type Cast Exceptions that popup with implicit casting in languages like C# and Python.
    – Branco
    Commented Aug 6, 2015 at 12:21
2

The field calc function you are after is concat() e.g.

concat( 'abc', 123)
3
  • Isn't this a purely SQL function?
    – Branco
    Commented Aug 4, 2015 at 18:04
  • Not sure but its available in qgis field calculator and I find it useful Commented Aug 4, 2015 at 18:30
  • Ok wasn't sure. I don't use QGIS often and only know it from Transect-SQL and string extension methods in .NET languages.
    – Branco
    Commented Aug 4, 2015 at 18:38
0

in Arcmap they given this example

http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004s000000

Concatenate two fields with a space separator

!SUB_REGION! + " " + !STATE_ABBR! in python

0

I would recommend using the format method of the string class to perform this type of operation. Here is a link to a similar question:

Concatenating string and numeric data in ArcGIS

As a general rule you should avoid using concatenation in favour of the format method. You will have cleaner code and more control over the final output string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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