2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
34
Task/Comma-quibbling/PureBasic/comma-quibbling.purebasic
Normal file
34
Task/Comma-quibbling/PureBasic/comma-quibbling.purebasic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
EnableExplicit
|
||||
|
||||
Procedure.s CommaQuibble(Input$)
|
||||
Protected i, count
|
||||
Protected result$, word$
|
||||
Input$ = RemoveString(Input$, "[")
|
||||
Input$ = RemoveString(Input$, "]")
|
||||
Input$ = RemoveString(Input$, #DQUOTE$)
|
||||
count = CountString(Input$, ",") + 1
|
||||
result$ = "{"
|
||||
For i = 1 To count
|
||||
word$ = StringField(Input$, i, ",")
|
||||
If i = 1
|
||||
result$ + word$
|
||||
ElseIf Count = i
|
||||
result$ + " and " + word$
|
||||
Else
|
||||
result$ + ", " + word$
|
||||
EndIf
|
||||
Next
|
||||
ProcedureReturn result$ + "}"
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
; As 3 of the strings contain embedded quotes these need to be escaped with '\' and the whole string preceded by '~'
|
||||
PrintN(CommaQuibble("[]"))
|
||||
PrintN(CommaQuibble(~"[\"ABC\"]"))
|
||||
PrintN(CommaQuibble(~"[\"ABC\",\"DEF\"]"))
|
||||
PrintN(CommaQuibble(~"[\"ABC\",\"DEF\",\"G\",\"H\"]"))
|
||||
PrintN("")
|
||||
PrintN("Press any key to close the console")
|
||||
Repeat: Delay(10) : Until Inkey() <> ""
|
||||
CloseConsole()
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue