Text Functions

Hello

I need to split a big text(200 characters let's say) so that at each 4th character I want to insert a new line.
The purpose is to display this big text in a paging grid.
Any ideas ?
Thanks in advance !

Ovidiu


OriginalPostID-251160

  Discussion posts and replies are publicly visible

Parents
  • The code above won't quite work - try running it with a text value of "123412341234123412" and you'll see the problems. Not only does it not insert at the correct locations, it also truncates the text if the length isn't divisible by the length that's required for the split.

    This problem is a bit tricky due to the way insert works; it would seem that, for a split of length 4, that the correct insert locations would be {5, 10, 15, 20} but that's not actually the case - they should actually be {5, 9, 13, 17} as insert does all the inserts at once and doesn't re-evaluate the string each time an entry is inserted.

    I've attached a modified piece of code that behaves as required. As @chetany has said, simply replace "@" at line 23 with char(10) to see the results as required.

    split_text.txt

Reply
  • The code above won't quite work - try running it with a text value of "123412341234123412" and you'll see the problems. Not only does it not insert at the correct locations, it also truncates the text if the length isn't divisible by the length that's required for the split.

    This problem is a bit tricky due to the way insert works; it would seem that, for a split of length 4, that the correct insert locations would be {5, 10, 15, 20} but that's not actually the case - they should actually be {5, 9, 13, 17} as insert does all the inserts at once and doesn't re-evaluate the string each time an entry is inserted.

    I've attached a modified piece of code that behaves as required. As @chetany has said, simply replace "@" at line 23 with char(10) to see the results as required.

    split_text.txt

Children
No Data