diff --git a/public/usage-examples-images-gifs/utilities/is_integer-1-basic.gif b/public/usage-examples-images-gifs/utilities/is_integer-1-basic.gif new file mode 100644 index 000000000..4f70063d5 Binary files /dev/null and b/public/usage-examples-images-gifs/utilities/is_integer-1-basic.gif differ diff --git a/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic-oop.cs b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic-oop.cs new file mode 100644 index 000000000..48b822984 --- /dev/null +++ b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic-oop.cs @@ -0,0 +1,54 @@ +// Usage Example for: https://splashkit.io/api/text/#is-integer +// Goal: I am reading text and I am printing whether each line is an integer. +// Why: I am showing how to use IsInteger inside a small class. +// Controls: I am typing q or quit to exit. + +using SplashKitSDK; + +namespace UtilitiesExamples +{ + public class IsIntegerRepl + { + public void Run() + { + SplashKit.WriteLine("Is Integer Checker (OOP)"); + SplashKit.WriteLine("Type a value and press Enter. Type q to quit."); + + bool running = true; + while (running) + { + SplashKit.Write("> "); + string? text = SplashKit.ReadLine(); + + if (text == null) + { + break; + } + + if (text == "q" || text == "quit") + { + running = false; + } + else + { + // I am using IsInteger so I am learning the utility call + if (SplashKit.IsInteger(text)) + { + SplashKit.WriteLine("Integer"); + } + else + { + SplashKit.WriteLine("Not integer"); + } + } + } + + SplashKit.WriteLine("Bye"); + } + + public static void Main() + { + new IsIntegerRepl().Run(); + } + } +} \ No newline at end of file diff --git a/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cpp b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cpp new file mode 100644 index 000000000..eef0fdd94 --- /dev/null +++ b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cpp @@ -0,0 +1,39 @@ +// Usage Example for: https://splashkit.io/api/text/#is-integer +// Goal: I am reading text and I am printing whether each line is an integer. +// Why: I am showing how to use is_integer in a simple REPL. +// Controls: I am typing q or quit to exit. + +#include "splashkit.h" + +int main() +{ + write_line("Is Integer Checker"); + write_line("Type a value and press Enter. Type q to quit."); + + bool running = true; + while (running) + { + write("> "); + string text = read_line(); + + if (text == "q" || text == "quit") + { + running = false; + } + else + { + // I am using is_integer so I am learning the utility call + if (is_integer(text)) + { + write_line("Integer"); + } + else + { + write_line("Not integer"); + } + } + } + + write_line("Bye"); + return 0; +} \ No newline at end of file diff --git a/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cs b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cs new file mode 100644 index 000000000..86933f675 --- /dev/null +++ b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.cs @@ -0,0 +1,41 @@ +// Usage Example for: https://splashkit.io/api/text/#is-integer +// Goal: I am reading text and I am printing whether each line is an integer. +// Why: I am showing how to use IsInteger in a simple REPL. +// Controls: I am typing q or quit to exit. + +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +WriteLine("Is Integer Checker"); +WriteLine("Type a value and press Enter. Type q to quit."); + +bool running = true; +while (running) +{ + Write("> "); + string? text = ReadLine(); + + if (text == null) + { + break; + } + + if (text == "q" || text == "quit") + { + running = false; + } + else + { + // I am using IsInteger so I am learning the utility call + if (IsInteger(text)) + { + WriteLine("Integer"); + } + else + { + WriteLine("Not integer"); + } + } +} + +WriteLine("Bye"); \ No newline at end of file diff --git a/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.py b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.py new file mode 100644 index 000000000..ac27d93f4 --- /dev/null +++ b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.py @@ -0,0 +1,31 @@ +# Usage Example for: https://splashkit.io/api/text/#is-integer +# Goal: I am reading text and I am printing whether each line is an integer. +# Why: I am showing how to use an integer check in a simple REPL. +# Controls: I am typing q or quit to exit. + +def is_integer_text(s: str) -> bool: + # I am checking if s is an integer (leading +/- allowed) + if not s: + return False + if s[0] in '+-': + s = s[1:] + return s.isdigit() + +print("Is Integer Checker (Python)") +print("Type a value and press Enter. Type q to quit.") + +while True: + try: + text = input("> ") + except EOFError: + break + + if text == "q" or text == "quit": + break + + if is_integer_text(text): + print("Integer") + else: + print("Not integer") + +print("Bye") \ No newline at end of file diff --git a/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.txt b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.txt new file mode 100644 index 000000000..77c3ad375 --- /dev/null +++ b/src/assets/usage-examples-code/utilities/is_integer/is_integer-1-basic.txt @@ -0,0 +1 @@ +I am reading text lines and I am printing whether each is an integer; I am exiting when I type q. \ No newline at end of file