0

I have imported CAD annotation and changed it to point feature, and I have the "text string" field in table attribute. Now I want to filter any records that contain the text in parentheses. For example: the text is "100PVC (2005)" => I want to get "2005" But the field is more complicated than this example, because some records just like "(05-07)". I have tried the index function with field calculator but it did not work. I also could not select records which contain the parentheses by using the Select by Attributes. My expression was:

[TextString] LIKE '%(____)%'

When I verify that it was successfully but no records were returned.

How can I solve this problem?

2

Try replacing the text between the parenthesis with another % sign eg:

"NAME" LIKE '%(%)%'

This should select all rows with opening and closing parenthesis from my NAME field

| improve this answer | |
2

For this I would recommend coming to grips with how to use the Field Calculator with the Python parser. This is described using examples in the Online Help but in the case of your specific example I would use something like this:

Parser:

Python

Expression:

Reclass(!TextString!)

Code Block:

def Reclass(string):
    if string == None:
        return None
    else:
        if "(" in string:
            textInParentheses = string[string.find("(")+1:string.find(")")]
            if "-" in string:
                return "20" + textInParentheses [0:2]
            else:
                return textInParentheses
        else:
            return string

Hopefully, this will give you something to work from in order to address all your business rules. The above just looks for what's between "(" and ")" and if it has a hyphen then just grab the first two characters and put "20" in front of it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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