Change a certain string of an automatically printed number in swift 4
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
add a comment |
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
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 |
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
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
asked Nov 19 at 11:36
Michele Russo
31
31
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
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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
12.4k43253
12.4k43253
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 |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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