Change a certain string of an automatically printed number in swift 4












0















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























  • Whats the issue? Looks alright to me

    – Scriptable
    Nov 19 '18 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 '18 at 11:43











  • I think I understand what you mean.. check my answer below

    – Scriptable
    Nov 19 '18 at 11:45
















0















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























  • Whats the issue? Looks alright to me

    – Scriptable
    Nov 19 '18 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 '18 at 11:43











  • I think I understand what you mean.. check my answer below

    – Scriptable
    Nov 19 '18 at 11:45














0












0








0


0






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














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













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 11:36









Michele RussoMichele Russo

31




31













  • Whats the issue? Looks alright to me

    – Scriptable
    Nov 19 '18 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 '18 at 11:43











  • I think I understand what you mean.. check my answer below

    – Scriptable
    Nov 19 '18 at 11:45



















  • Whats the issue? Looks alright to me

    – Scriptable
    Nov 19 '18 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 '18 at 11:43











  • I think I understand what you mean.. check my answer below

    – Scriptable
    Nov 19 '18 at 11:45

















Whats the issue? Looks alright to me

– Scriptable
Nov 19 '18 at 11:40





Whats the issue? Looks alright to me

– Scriptable
Nov 19 '18 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 '18 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 '18 at 11:43













I think I understand what you mean.. check my answer below

– Scriptable
Nov 19 '18 at 11:45





I think I understand what you mean.. check my answer below

– Scriptable
Nov 19 '18 at 11:45












1 Answer
1






active

oldest

votes


















1














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 '18 at 11:54











  • oh okay I solved thanks a lot of your answer :)

    – Michele Russo
    Nov 19 '18 at 11:56











  • glad to of helped, good luck with the project

    – Scriptable
    Nov 19 '18 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',
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
});


}
});














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









1














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 '18 at 11:54











  • oh okay I solved thanks a lot of your answer :)

    – Michele Russo
    Nov 19 '18 at 11:56











  • glad to of helped, good luck with the project

    – Scriptable
    Nov 19 '18 at 12:34
















1














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 '18 at 11:54











  • oh okay I solved thanks a lot of your answer :)

    – Michele Russo
    Nov 19 '18 at 11:56











  • glad to of helped, good luck with the project

    – Scriptable
    Nov 19 '18 at 12:34














1












1








1







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 '18 at 11:45









ScriptableScriptable

13.2k43554




13.2k43554













  • I always print the 0 in the playground

    – Michele Russo
    Nov 19 '18 at 11:54











  • oh okay I solved thanks a lot of your answer :)

    – Michele Russo
    Nov 19 '18 at 11:56











  • glad to of helped, good luck with the project

    – Scriptable
    Nov 19 '18 at 12:34



















  • I always print the 0 in the playground

    – Michele Russo
    Nov 19 '18 at 11:54











  • oh okay I solved thanks a lot of your answer :)

    – Michele Russo
    Nov 19 '18 at 11:56











  • glad to of helped, good luck with the project

    – Scriptable
    Nov 19 '18 at 12:34

















I always print the 0 in the playground

– Michele Russo
Nov 19 '18 at 11:54





I always print the 0 in the playground

– Michele Russo
Nov 19 '18 at 11:54













oh okay I solved thanks a lot of your answer :)

– Michele Russo
Nov 19 '18 at 11:56





oh okay I solved thanks a lot of your answer :)

– Michele Russo
Nov 19 '18 at 11:56













glad to of helped, good luck with the project

– Scriptable
Nov 19 '18 at 12:34





glad to of helped, good luck with the project

– Scriptable
Nov 19 '18 at 12:34




















draft saved

draft discarded




















































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.




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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()