Split string in multiples lines swift - string

I'm trying to split a string in multiple lines (such as the text of a song); I'm working in the localizable.strings.
I'd like to do something like this:
"TITLE_SONG01" = "It's my life";
"SUBTITLE_SONG01" = "";
"TEXT_SONG01" = "It's my life" +
"is now or never";
but it doesn't work because data isn't in the correct format. Can anyone help me?

You can do that by inserting "\n" where you want the new line to start. For example:
print("Hello\nWorld")
Which will output the Hello on one line and World on another like this:
Hello
World

Related

How can I do line breaks in a formatted string string python3

simple question that I hope has a simple answer
I want to store a formatted string to pass later to function call. I would like to have line breaks baked into one long string rather than send a string for each line. So for example
b = f'hello \n world'
b
this gives me 'hello \n world' which is not what I want.
How can I do this in a compact manner. I would prefer to avoid joins or something like that with a newline separator.
Thanks in advance.

How do I take a string and turn it into a list using SCALA?

I am brand new to Scala and having a tough time figuring this out.
I have a string like this:
a = "The dog crossed the street"
I want to create a list that looks like below:
a = List("The","dog","crossed","the","street")
I tried doing this using .split(" ") and then returning that, but it seems to do nothing and returns the same string. Could anyone help me out here?
It's safer to split() on one-or-more whitespace characters, just in case there are any tabs or adjacent spaces in the mix.
split() returns an Array so if you want a List you'll need to convert it.
"The dog\tcrossed\nthe street".split("\\s+").toList
//res0: List[String] = List(The, dog, crossed, the, street)

How to print specific number of words from a string in scala?

I have a strings:
str = "this is a great place...."
I want to print only 30 words from this string. How to do that?
Use split and take methods:
val str = "this is a great place...."
str.split("\\W").take(30).mkString(" ")
// res0: String = this is a great place
You could just do something like:
"""(\b\w+\b\W*){0,30}""".r findPrefixOf "this is a great place...."
Or using a different notation:
"""(\b\w+\b\W*){0,30}""".r.findPrefixOf("this is a great place....")
Here is some pseudo code you can work with
Split string using the split method into an Array[String] of the words.
Iterate across the array and concatenate the words together that you want to include
Print out the string
I can't think of any external libraries or built-in functions that will do that for you. You will need to write your own code to do this.

Importing String with variables from Txt file

I need to import text from txt file with some variables. I use BufferedReader and File Reader. In code I have :
String car = "vw golf";
String color = "nice sunny blue color";
And in my txt file:
I have nice " +car+ " which has "+color+".
My expected output :
I have nice vw golf which has nice sunny blue color.
My actual output is :
I have nice " +car+ " which has "+color+".
If I've understood correctly, what you want to do is replace " + car + " with the value of your car string and likewise for colour. You've tried to do this by writing your text file as if it were a command to be evaluated. However, that won't happen - it will just be outputted as is. I'm going to assume you are using c#. What you need to do is, prior to outputting your string, parse it to replace the markers with the variables. I would recommend you get rid of the double quotes in your text file. You could then do something like this:
string text = this.ReadTextFromFile();
string ammended = text.Replace("+car+", car);
As mentioned, this is assuming you remove the double quotes from your text file so it reads:
I have nice +car+ which has +color+.
Also, you don't need to use the + symbols, but I suppose they are a good way of designating a unique token to be replaced. You could use {car} in the file and then likewise in the Replace startment, for example.
I may not have properly understood what you wanted to do, of course!
Edit: Incase of confustion,
this.ReadTextFile();
was just a short hand way of saying that the text variable contains the contents as read from your text file.

how to split a string or make chars in vb 2010

I searched but nothing explains how to do this,
for example
Dim sentence as String = "cat is an animal"
if i make a msgbox :
MsgBox(sentence)
it shows
cat is an animal
how to make a msgbox that says
cat
is
an
animal.
Easy way Replace space with new line
as in string words = MyString.Replace(" ","\r\n")
Split would be split on space in to an array , and then join that back up with new lines which is pointless unless you need the array for something else.

Resources