Will the problem will be resolved if i add trim ?
Have you looked at the documentation for String#trim()? What is the value of SOH? Is it 0x0001? What will happen if they have managed to get the SOH in the middle of the text?
Joseph Michael wrote:. . . 1. Will the problem will be resolved if i add trim ??
Can you use the usual methods for finding whether a String contains a particular substring or character?
2. How to figure out whether a string has start of header character at the prefix or in the suffix and remove them ?
How are your users getting an SOH into the text box in the first place? What is the risk to your program if your users insert non‑printing characters into text? If you throw an exception, how is the user going to know about it, and what are they going to do about it? How difficult would it be to remove non‑printing characters from your text?
3. Is it good to remove the start of header character or throw exception to the user as it contains illegal character . . .
Joseph Michael wrote:What would be the best approach in this case?
Joseph Michael wrote:This is not a XML...Just a user alphabetical character string..Where SOH is exist in start of the string or middle of the string or in the end of the string...How to restrict this in Java?
...and any other non‑printing characters. Have you worked out how much of a threat such non‑printing characters pose to your program?
Paul Clapham wrote:. . . just delete that character . . .
Don't know. Please supply more details.
Joseph Michael wrote:. . . StringUtils . . . Is that would cause any issue?