Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

Is there a multi-line string syntax in Netlogo?

In Python there is a way to store long, multi-line text into a variable like so:

    a_string = """
          This is a very long string
          that spans multiple lines
          and I do not need to worry about
          line breaks
    """

My question: Is there a similar thing in NetLogo where I can just encase a block of text into special characters and store into a variable? Any alternative ways, such as string concatenation will work too, like so:

a_string = "This is a very long string"
           + "and I might need to use some regexes"
           + "to get it into this format
"
           + "as long as it's possible to do so."
           

So far I could not find anything like the former example, have not really searched for the latter as the former is my preference, but would appreciate any other alternatives.

question from:https://stackoverflow.com/questions/65923922/is-there-a-multi-line-string-syntax-in-netlogo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The word primitive should be able to do what you want. Just make sure to surround it with parentheses to handle multiple values. Example:

to set-a-string
  let a_string (word "This is a very long string"
           "and I might need to use some regexes"
           "to get it into this format
"
           "as long as it's possible to do so.")
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...