Hello,
Trying to get my label expression to work here. The problem is some of my table
records have a double quote in it (" symbol). I want to rename as such see example below:
(30" PVC Pipe Drain) and rename it to (30 inch)
I use the following vbScript - but get nowhere:
Function FindLabel ( [NAME] )
If Not IsNull([NAME]) Then
NewStr = Replace([NAME], "30'' PVC Pipe Drain", "30 inch")
FindLabel = NewStr
End If
End Function
--- also I tried python and get nowhere:
def FindLabel ( [NAME] 😞
S = [NAME]
S = S.replace( '30'' Drain, Vitreous Clay Pipe', '30 in')
return S
Solved! Go to Solution.
Caught that and fixed it in my post just before I saw your reply. Retry the code.
Okay, You have hooked me. Now, I cannot get it to work. I used your code. Do you post the code in the code block? What do you enter into the "Name=" block? Do you have to create another field to populate?
Thanks
No problem Richard please see snapshot below and here is the code that worked for me.
Function FindLabel ( [Name] )
dblQuote = instr( [Name] ,chr(34))
if dblQuote > 0 then
newStr = left( [Name] ,dblQuote - 1) & " inch"
else
newStr = [Name]
end if
FindLabel = newStr
End Function
The code has been written to work as an Advanced Label Expression, not as a field calculation. For a field calculation I would write it like:
Parser: VB Script
Use Codeblock: Checked
Pre-Logic Codeblock:
Output = [NAME] dblQoute = instr(Output, chr(34)) if dblQuote > 0 Then Output = Left(Output, dblQuote - 1) & " inch"
NAME= Output
I edited my previous post to remove quote (really skipping over it ) and shorten the label
"Thank You" Ted & Richard. Both your suggestions have worked for me - hope they work for other GIS users. Very much appreciated!!
To make all quotes turn into " inch" your VB Script label code should be:
Function FindLabel ( [NAME] )
If Not IsNull([NAME]) Then
NewStr = Replace([NAME], "''"", " inch")
FindLabel = NewStr
End If
End Function
This assumes no quote character in your data is a real quote character and always changes to inch. If that is true, you should not have to deal with the full field value in your features, just the quote character.
M.Neer,
Another quick fix is to start an edit session, open up the attribute table, click on the table options and select the find and replace. Replace the (") with nothing (just leave blank). Save. I am still looking to do this through Python.
James
M.Neer,
Sorry, but replace INCH not blank. I going to use your code. Excellent Job!!
James
I am an old vb guy struggling to learn python..... for the challenge I attempted to get a python script to work as well.....
Bear in mind this is probably sloppy python but it works....
def FindLabel ([TestChar]): str = [TestChar] i = str.find(chr(34)) if i > 0: newStr = str[:i] + " inch" else: newStr = str return newStr