Hi,
I have a list as follows;
Object ID Field 1
1 Example,Example
2 ,Example,Example,Example
3 ,Example
I want to remove just the first comma.
I would appreciate your assistance.
lots of ways, but a simple code block might do it
# ---- code block
def func(a):
if a[0] == ',':
return a[1:]
else:
return a
# --- 'a' is your field name with the python parser, the expression would be
# func(!YourFieldNameHere!
a = 'Example,Example'
a
'Example,Example'
b = ',Example,Example,Example'
func(b)
'Example,Example,Example'
Hi Dan, thanks for this however it doesn't seem to work. I replaced 'a' with my field name. I am using field calculator. Do i have to add anything in codeblock?
Set the field calculator to following for the second example
And if you are getting an error, then show it.
As for the code block, nothing needs to be changed, but your expression box would call the function with
func(!fieldnamehere!)
Of course, python parser and you are calculating values in a new text field.
Done it. Thanks.
Adil... perhaps you could mark the thread Answered with the one that provided you the answer so others know a solution was reached and what one was used
Or more simply as a straight field calculation... python parser
replace 'a' with your field name in exclamation marks as above
a = ',Example,Example,Example'
[a, a[1:]][a[0] == ',']
Out[27]: 'Example,Example,Example'
In case you have multiple commas at the start you could use this function in the code block:
def EliminateStartignCommas(txt):
while txt[0] == ',':
txt = txt[1:]
return txt
You could also use txt.lstrip(",")
And just to play devils advocate.... What about a find and replace for " , " at the start of the field?