0 Favourites

How do I format Ajax impored text

  • Hi everyone,

    What do I use to add linebreaks in text that I import from a json file?

    When I use "some text" & newline the import breaks.

  • Hi everyone,

    What do I use to add linebreaks in text that I import from a json file?

    When I use "some text" & newline the import breaks.

    You can use tokenat to put line breaks into your text.

    So if your separator is "|" put that character in your text where you want line breaks. Then you can say something like:

    set text to: tokenat("some text",0,"|")&newline&tokenat("some text",1,"|")

  • Artpunk Good idea, thanks!

  • Artpunk

    hm, so here I am trying to replace placeholder characters with linebreaks in my imported array.

    I seem to not get the syntax right, what I do is:

    On Ajax import complete:

    for each X element: set value at LOOPINDEX to replace( str(Array.At(LOOPINDEX), "|", "&newline&" )

    not sure about array expressions ... can someone enlighten me, what's wrong here?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • It's easier to use replace() expression:

    Set s to "Hi there!^How are you?^Take a seat."

    Set s to replace(s, "^", newline)

  • hey dop2000 !

    yeah, thats what i do, i just now figured out what i had missed: I am in fact using two dimensions, hence i needed to fix the index.

    new problem now, to insert a linebreak in a string i need to interrupt the string.

    how do i get quotes attached before and after &newline& ?

  • I don't understand your question. Why do you need quotes?

    Your source string is this:

    sourceString= "Lorem ipsum dolor sit amet.&newline&Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&newline&Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&newline&Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

    You do

    set targetString to replace(sourceString, "&newline&", newline)

    And when you display targetString on the screen, there should be line breaks where needed.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)