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())









share|improve this question







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















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())









share|improve this question







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













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())









share|improve this question







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






share|improve this question







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.











share|improve this question







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.









share|improve this question




share|improve this question






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


















  • 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












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
}





share|improve this answer





















  • 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











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',
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
});


}
});






Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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








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
}





share|improve this answer





















  • 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















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
}





share|improve this answer





















  • 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













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
}





share|improve this answer












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
}






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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










Michele Russo is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory