topcat3
topcat3

Reputation: 2642

Parsing a String Java

I have the following fields in my XML

<NOPC_NOTE_LINE1></NOPC_NOTE_LINE1>
<NOPC_NOTE_LINE2><NOPC_NOTE_LINE2>
<NOPC_NOTE_LINE3><NOPC_NOTE_LINE3>

In my JAVA code I have

service028.setNote1();
service028.setNote2();
service028.setNote3();

setnote2 can only take a max of 60 characters. The user should be able to enter 110 characters. If the user enters more than 60 characters I want to take the remaining characters and put them into setNote3 which should allow 50 characters

Any good way to do this?

Upvotes: 0

Views: 90

Answers (1)

kaya
kaya

Reputation: 1666

try this

        if (stringValue.length() > 60) {
            service028.setNote2(stringValue.substring(0, 60));
            service028.setNote3(stringValue.substring(60));
        } else {
            service028.setNote2(stringValue);
        }

Upvotes: 1

Related Questions