Change a certain string of an automatically printed number in swift 4
up vote
0
down vote
favorite
I wanted to copy this page http://www.99-bottles-of-beer.net/lyrics.html in IOS playground to practice but I would like to ask a question and I hope for your help. I created a function called vantanoveBottles, created a variable "texts" of type String and used "for and in" for numbers from 0 ... 5 I created a string constancy in which I entered numbers and text and then I added texts + newLine as in the code.Now if you compare the site when it comes to 1 and says that there are no more beers do not use the number 0, instead I get out so I would basically print example numbers from 1 to 98 inverse with string of text, (and I did this) then come to 1 should not go out "1 bottles of beer on the wall, 1 bottles of beer. n" Take one down and pass it around, 0 bottles of beer on the wall. " the 0 must be eliminated must not go out, how do I do? This is a test code
func novantanoveBottles () ->String {
var testi: String = ""
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around, (numeri - 1) bottles of beer on the wall. n"
testi += newLine
}
testi += "n n n No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall."
return testi
}
print(novantanoveBottles())
ios swift4
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I wanted to copy this page http://www.99-bottles-of-beer.net/lyrics.html in IOS playground to practice but I would like to ask a question and I hope for your help. I created a function called vantanoveBottles, created a variable "texts" of type String and used "for and in" for numbers from 0 ... 5 I created a string constancy in which I entered numbers and text and then I added texts + newLine as in the code.Now if you compare the site when it comes to 1 and says that there are no more beers do not use the number 0, instead I get out so I would basically print example numbers from 1 to 98 inverse with string of text, (and I did this) then come to 1 should not go out "1 bottles of beer on the wall, 1 bottles of beer. n" Take one down and pass it around, 0 bottles of beer on the wall. " the 0 must be eliminated must not go out, how do I do? This is a test code
func novantanoveBottles () ->String {
var testi: String = ""
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around, (numeri - 1) bottles of beer on the wall. n"
testi += newLine
}
testi += "n n n No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall."
return testi
}
print(novantanoveBottles())
ios swift4
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wanted to copy this page http://www.99-bottles-of-beer.net/lyrics.html in IOS playground to practice but I would like to ask a question and I hope for your help. I created a function called vantanoveBottles, created a variable "texts" of type String and used "for and in" for numbers from 0 ... 5 I created a string constancy in which I entered numbers and text and then I added texts + newLine as in the code.Now if you compare the site when it comes to 1 and says that there are no more beers do not use the number 0, instead I get out so I would basically print example numbers from 1 to 98 inverse with string of text, (and I did this) then come to 1 should not go out "1 bottles of beer on the wall, 1 bottles of beer. n" Take one down and pass it around, 0 bottles of beer on the wall. " the 0 must be eliminated must not go out, how do I do? This is a test code
func novantanoveBottles () ->String {
var testi: String = ""
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around, (numeri - 1) bottles of beer on the wall. n"
testi += newLine
}
testi += "n n n No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall."
return testi
}
print(novantanoveBottles())
ios swift4
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I wanted to copy this page http://www.99-bottles-of-beer.net/lyrics.html in IOS playground to practice but I would like to ask a question and I hope for your help. I created a function called vantanoveBottles, created a variable "texts" of type String and used "for and in" for numbers from 0 ... 5 I created a string constancy in which I entered numbers and text and then I added texts + newLine as in the code.Now if you compare the site when it comes to 1 and says that there are no more beers do not use the number 0, instead I get out so I would basically print example numbers from 1 to 98 inverse with string of text, (and I did this) then come to 1 should not go out "1 bottles of beer on the wall, 1 bottles of beer. n" Take one down and pass it around, 0 bottles of beer on the wall. " the 0 must be eliminated must not go out, how do I do? This is a test code
func novantanoveBottles () ->String {
var testi: String = ""
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around, (numeri - 1) bottles of beer on the wall. n"
testi += newLine
}
testi += "n n n No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall."
return testi
}
print(novantanoveBottles())
ios swift4
ios swift4
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 19 at 11:36


Michele Russo
31
31
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Michele Russo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45
add a comment |
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around"
if numeri != 1 {
test1 += ", (numeri - 1) bottles of beer on the wall. n
} else {
test1 += ".n"
}
testi += newLine
}
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around"
if numeri != 1 {
test1 += ", (numeri - 1) bottles of beer on the wall. n
} else {
test1 += ".n"
}
testi += newLine
}
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
add a comment |
up vote
1
down vote
accepted
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around"
if numeri != 1 {
test1 += ", (numeri - 1) bottles of beer on the wall. n
} else {
test1 += ".n"
}
testi += newLine
}
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around"
if numeri != 1 {
test1 += ", (numeri - 1) bottles of beer on the wall. n
} else {
test1 += ".n"
}
testi += newLine
}
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "n (numeri) bottles of beer on the wall, (numeri) bottles of beer.n Take one down and pass it around"
if numeri != 1 {
test1 += ", (numeri - 1) bottles of beer on the wall. n
} else {
test1 += ".n"
}
testi += newLine
}
answered Nov 19 at 11:45


Scriptable
12k43253
12k43253
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
add a comment |
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
I always print the 0 in the playground
– Michele Russo
Nov 19 at 11:54
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
oh okay I solved thanks a lot of your answer :)
– Michele Russo
Nov 19 at 11:56
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
glad to of helped, good luck with the project
– Scriptable
Nov 19 at 12:34
add a comment |
Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.
Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.
Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.
Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373804%2fchange-a-certain-string-of-an-automatically-printed-number-in-swift-4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Whats the issue? Looks alright to me
– Scriptable
Nov 19 at 11:40
if you are comparing the page, in last when it comes to "1 bottle of beer on the wall, 1 bottle of beer. "Do not print the number 0 instead I print it, how can I do to delete the 0 also me?
– Michele Russo
Nov 19 at 11:43
I think I understand what you mean.. check my answer below
– Scriptable
Nov 19 at 11:45