I am not sure what you mean by "various kinds of long characters". But for the example you have you could put the following line of JavaScript code in the calculate event of textfield2
textfield1.rawValue.split(",")[0]
This assumes that textfield2 and textfield1 are at the same level in the form structure as the textfield1 is a relative reference.