0

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?

9
  • Use an XML parser, add the lines to one string and then split as needed. Commented Jul 26, 2016 at 11:40
  • 1
    where are you stuck? you don't know how to measure the length of a String? how to cut it? show what you've done so far Commented Jul 26, 2016 at 11:41
  • whats with setnote1? how many characters there? Commented Jul 26, 2016 at 12:17
  • @kaya 60 characters allowed in each. setNote1 is taken up with prefilled text Commented Jul 26, 2016 at 12:31
  • @sharonbn yes I can String length() and then I have tried if(str.length() > 50) strOut = str.substring(0,49) + "..."; Commented Jul 26, 2016 at 12:33

1 Answer 1

1

try this

        if (stringValue.length() > 60) {
            service028.setNote2(stringValue.substring(0, 60));
            service028.setNote3(stringValue.substring(60));
        } else {
            service028.setNote2(stringValue);
        }
Sign up to request clarification or add additional context in comments.

4 Comments

did you mean "divide by 60"? also, no reason to only put 58 characters since OP allowed 60
ohh, long time since i used modulo, my bad im fixing this and trying right in IDE
You don't need those stringValue.length() bits. substring(n) goes from n to the end of the string anyway.
@kaya going to try now and let you know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.