Utilities
Functions
Contains
Returns true if the string contains the substring.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to search |
subtext | String | The substring to search for |
Return Type: Boolean
Signatures:
bool contains(const string &text, const string &subtext)
public static bool SplashKit.Contains(string text, string subtext);
def contains(text, subtext):
function Contains(const text: String; const subtext: String): Boolean
Usage:
Example 1: Checking if a string contains a word
#include "splashkit.h"
int main(){ string text = "Hello World, hello world"; string subtext = "World"; write_line("Text: " + text); write_line("Subtext: " + subtext);
// Check if "Hello World" contains "World" if (contains(text, subtext)) { write_line("The string contains 'World'."); } else { write_line("The string does not contain 'World'."); }}
using static SplashKitSDK.SplashKit;
string text = "Hello World, hello world";string subtext = "World";
WriteLine("Text: " + text);WriteLine("Subtext: " + subtext);
// Check if "Hello World" contains "World"if (Contains(text, subtext)){ WriteLine("Text contains 'World'.");}else{ WriteLine("Text does not contain 'World'.");}
using SplashKitSDK;
namespace ContainsExample{ public class Program { public static void Main() { string text = "Hello World, hello world"; string subtext = "World";
SplashKit.WriteLine("Text: " + text); SplashKit.WriteLine("Subtext: " + subtext);
// Check if "Hello World" contains "World" if (SplashKit.Contains(text, subtext)) { SplashKit.WriteLine("Text contains 'World'."); } else { SplashKit.WriteLine("Text does not contain 'World'."); } } }}
from splashkit import *
text = "Hello World, hello world"subtext = "World"
write_line("Text: " + text)write_line("Subtext: " + subtext)
# Check if "Hello World" contains "World"if contains(text, subtext): write_line("The string contains 'World'.")else: write_line("The string does not contain 'World'.")
Output:
Convert To Double
Convert the passed in string into a double. This can fail in an error if the value is not a number, consider using Is Number
to check before converting a string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to convert. |
Return Type: Double
Signatures:
double convert_to_double(const string &text)
public static double SplashKit.ConvertToDouble(string text);
def convert_to_double(text):
function ConvertToDouble(const text: String): Double
Usage:
Example 1: Simple Interest Calculator
#include "splashkit.h"
int main(){ write_line("Welcome to the Simple Interest Calculator!");
// Get principal amount from the user write_line("Please enter the principal amount (in dollars):"); string principal_input = read_line();
// Get the interest rate from the user write_line("Please enter the interest rate (as a percentage, e.g., 5 for 5%):"); string rate_input = read_line();
// Get the time period from the user write_line("Please enter the time period (in years):"); string time_input = read_line();
// Convert inputs to double double principal = convert_to_double(principal_input); double rate = convert_to_double(rate_input); double time = convert_to_double(time_input);
// Calculate simple interest: Interest = Principal * Rate * Time / 100 double interest = (principal * rate * time) / 100;
// Output the result write_line("Calculating interest..."); delay(1000);
write_line("For a principal of $" + std::to_string(principal) + " at an interest rate of " + std::to_string(rate) + "% over " + std::to_string(time) + " years:"); write_line("The simple interest is: $" + std::to_string(interest));
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Welcome to the Simple Interest Calculator!");
// Get principal amount from the userWriteLine("Please enter the principal amount (in dollars):");string principalInput = ReadLine();
// Get the interest rate from the userWriteLine("Please enter the interest rate (as a percentage, e.g., 5 for 5%):");string rateInput = ReadLine();
// Get the time period from the userWriteLine("Please enter the time period (in years):");string timeInput = ReadLine();
// Convert inputs to doubledouble principal = ConvertToDouble(principalInput);double rate = ConvertToDouble(rateInput);double time = ConvertToDouble(timeInput);
// Calculate simple interest: Interest = Principal * Rate * Time / 100double interest = (principal * rate * time) / 100;
// Output the resultWriteLine("Calculating interest...");Delay(1000);
WriteLine($"For a principal of ${principal} at an interest rate of {rate}% over {time} years:");WriteLine($"The simple interest is: ${interest}");
using SplashKitSDK;
namespace ConvertToDoubleExample{ public class Program { public static void Main() { SplashKit.WriteLine("Welcome to the Simple Interest Calculator!");
// Get principal amount from the user SplashKit.WriteLine("Please enter the principal amount (in dollars):"); string principalInput = SplashKit.ReadLine();
// Get the interest rate from the user SplashKit.WriteLine("Please enter the interest rate (as a percentage, e.g., 5 for 5%):"); string rateInput = SplashKit.ReadLine();
// Get the time period from the user SplashKit.WriteLine("Please enter the time period (in years):"); string timeInput = SplashKit.ReadLine();
// Convert inputs to double double principal = SplashKit.ConvertToDouble(principalInput); double rate = SplashKit.ConvertToDouble(rateInput); double time = SplashKit.ConvertToDouble(timeInput);
// Calculate simple interest: Interest = Principal * Rate * Time / 100 double interest = (principal * rate * time) / 100;
// Output the result SplashKit.WriteLine("Calculating interest..."); SplashKit.Delay(1000);
SplashKit.WriteLine($"For a principal of ${principal} at an interest rate of {rate}% over {time} years:"); SplashKit.WriteLine($"The simple interest is: ${interest}"); } }}
from splashkit import *
write_line("Welcome to the Simple Interest Calculator!")
# Get principal amount from the userwrite_line("Please enter the principal amount (in dollars):")principal_input = read_line()
# Get the interest rate from the userwrite_line("Please enter the interest rate (as a percentage, e.g., 5 for 5%):")rate_input = read_line()
# Get the time period from the userwrite_line("Please enter the time period (in years):")time_input = read_line()
# Convert inputs to doubleprincipal = convert_to_double(principal_input)rate = convert_to_double(rate_input)time = convert_to_double(time_input)
# Calculate simple interest: Interest = Principal * Rate * Time / 100interest = (principal * rate * time) / 100
# Output the resultwrite_line("Calculating interest...")delay(1000)
write_line(f"For a principal of ${principal} at an interest rate of {rate}% over {time} years:")write_line(f"The simple interest is: ${interest}")
Output:
Convert To Integer
Convert the passed in string into an integer. This can fail in an error if the value is not an integer, consider using Is Integer
to check before converting a string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to convert. |
Return Type: Integer
Signatures:
int convert_to_integer(const string &text)
public static int SplashKit.ConvertToInteger(string text);
def convert_to_integer(text):
function ConvertToInteger(const text: String): Integer
Usage:
Example 1: Guessing Game
#include "splashkit.h"
int main(){ write_line("Welcome to the Number Guessing Game!"); write_line("I'm thinking of a number between 1 and 100...");
string input; // User input int secret_number = 42; // Set a secret number int guess = -1; // Initialise with an invalid guess
while (guess != secret_number) { // Ask the user for their guess write_line("Please enter your guess:"); input = read_line();
// Validate if the input is a valid integer if (is_integer(input)) { // Convert input string to integer guess = convert_to_integer(input);
// Check if the guess is correct if (guess > secret_number) { write_line("Too high! Try again."); } else if (guess < secret_number) { write_line("Too low! Try again."); } } else { write_line("That's not a valid integer! Please enter a number."); } }
write_line("Congratulations! You've guessed the correct number: " + std::to_string(guess));
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Welcome to the Number Guessing Game!");WriteLine("I'm thinking of a number between 1 and 100...");
string input; // User inputint secretNumber = 42; // Set a secret numberint guess = -1; // Initialise with an invalid guess
while (guess != secretNumber){ // Ask the user for their guess WriteLine("Please enter your guess:"); input = ReadLine();
// Validate if the input is a valid integer if (IsInteger(input)) { // Convert input string to integer guess = ConvertToInteger(input);
// Check if the guess is correct if (guess > secretNumber) { WriteLine("Too high! Try again."); } else if (guess < secretNumber) { WriteLine("Too low! Try again."); } } else { WriteLine("That's not a valid integer! Please enter a number."); }}
WriteLine($"Congratulations! You've guessed the correct number: {guess}");
using SplashKitSDK;
namespace ConvertToIntegerExample{ public class Program { public static void Main() { SplashKit.WriteLine("Welcome to the Number Guessing Game!"); SplashKit.WriteLine("I'm thinking of a number between 1 and 100...");
string input; // User input int secretNumber = 42; // Set a secret number int guess = -1; // Initialise with an invalid guess
while (guess != secretNumber) { // Ask the user for their guess SplashKit.WriteLine("Please enter your guess:"); input = SplashKit.ReadLine();
// Validate if the input is a valid integer if (SplashKit.IsInteger(input)) { // Convert input string to integer guess = SplashKit.ConvertToInteger(input);
// Check if the guess is correct if (guess > secretNumber) { SplashKit.WriteLine("Too high! Try again."); } else if (guess < secretNumber) { SplashKit.WriteLine("Too low! Try again."); } } else { SplashKit.WriteLine("That's not a valid integer! Please enter a number."); } }
SplashKit.WriteLine($"Congratulations! You've guessed the correct number: {guess}"); } }}
from splashkit import *
write_line("Welcome to the Number Guessing Game!")write_line("I'm thinking of a number between 1 and 100...")
input = ""; # User inputsecret_number = 42; # Set a secret numberguess = -1; # Initialise with an invalid guess
while guess != secret_number: # Ask the user for their guess write_line("Please enter your guess:") input_value = read_line()
# Validate if the input is a valid integer if is_integer(input_value): # Convert input string to integer guess = convert_to_integer(input_value)
# Check if the guess is correct if guess > secret_number: write_line("Too high! Try again.") elif guess < secret_number: write_line("Too low! Try again.") else: write_line("That's not a valid integer! Please enter a number.")
write_line(f"Congratulations! You've guessed the correct number: {guess}")
Output:
Index Of
Returns the index of the first occurrence of the substring in the text.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to search |
subtext | String | The substring to search for |
Return Type: Integer
Signatures:
int index_of(const string &text, const string &subtext)
public static int SplashKit.IndexOf(string text, string subtext);
def index_of(text, subtext):
function IndexOf(const text: String; const subtext: String): Integer
Usage:
Example 1: Check the index of a given word in a string
#include "splashkit.h"
int main(){ // Get sentence input from the user write_line("Enter a sentence:"); string sentence = read_line();
// Get the word to search for write_line("Enter the word to search for:"); string word = read_line();
// Find index of the word in the sentence int index = index_of(sentence, word);
// Display results based on whether the word was found or not if (index != -1) { write_line("The word '" + word + "' starts at index: " + std::to_string(index)); } else { write_line("The word '" + word + "' was not found in the sentence."); }
return 0;}
using static SplashKitSDK.SplashKit;
// Get sentence input from the userWriteLine("Enter a sentence:");string sentence = ReadLine();
// Get the word to search forWriteLine("Enter the word to search for:");string word = ReadLine();
// Find index of the word in the sentenceint index = IndexOf(sentence, word);
// Display results based on whether the word was found or notif (index != -1){ WriteLine($"The word '{word}' starts at index: {index}");}else{ WriteLine($"The word '{word}' was not found in the sentence.");}
using SplashKitSDK;
namespace IndexOfExample{ public class Program { public static void Main() { // Get sentence input from the user SplashKit.WriteLine("Enter a sentence:"); string sentence = SplashKit.ReadLine();
// Get the word to search for SplashKit.WriteLine("Enter the word to search for:"); string word = SplashKit.ReadLine();
// Find index of the word in the sentence int index = SplashKit.IndexOf(sentence, word);
// Display results based on whether the word was found or not if (index != -1) { SplashKit.WriteLine($"The word '{word}' starts at index: {index}"); } else { SplashKit.WriteLine($"The word '{word}' was not found in the sentence."); } } }}
from splashkit import *
# Get sentence input from the userwrite_line("Enter a sentence:")sentence = read_line()
# Get the word to search forwrite_line("Enter the word to search for:")word = read_line()
# Find index of the word in the sentenceindex = index_of(sentence, word)
# Display results based on whether the word was found or notif index != -1: write_line(f"The word '{word}' starts at index: {index}")else: write_line(f"The word '{word}' was not found in the sentence.")
Output:
Is Double
Checks if a string contains a number.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to check. |
Return Type: Boolean
Signatures:
bool is_double(const string &text)
public static bool SplashKit.IsDouble(string text);
def is_double(text):
function IsDouble(const text: String): Boolean
Usage:
Example 1: Double type?
#include "splashkit.h"
int main(){ string values[6] = {"123", "45.67", "-50", "abc", "789", "0"};
for (int i = 0; i < 6; i++) { // Print the value along with the result using "true" or "false" write(values[i] + " - ");
// Check if string is a valid double if (is_double(values[i])) write_line("true"); else write_line("false"); }
return 0;}
using static SplashKitSDK.SplashKit;
string[] values = { "123", "45.67", "-50", "abc", "789", "0" };
foreach (string value in values){ // Print the value along with the result using "true" or "false" Write(value + " - ");
// Check if string is a valid double if (IsDouble(value)) WriteLine("true"); else WriteLine("false");}
using SplashKitSDK;
namespace IsDoubleExample{ public class Program { public static void Main() { string[] values = { "123", "45.67", "-50", "abc", "789", "0" };
foreach (string value in values) { // Print the value along with the result using "true" or "false" SplashKit.Write(value + " - ");
// Check if string is a valid double if (SplashKit.IsDouble(value)) SplashKit.WriteLine("true"); else SplashKit.WriteLine("false"); } } }}
from splashkit import *
values = ["123", "45.67", "-50", "abc", "789", "0"]
for value in values: # Print the value along with the result using "true" or "false" write(f"{value} - ")
# Check if string is a valid double if (is_double(value)): write_line("true") else: write_line("false")
Output:
Is Integer
Checks if a string contains an integer value.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to check. |
Return Type: Boolean
Signatures:
bool is_integer(const string &text)
public static bool SplashKit.IsInteger(string text);
def is_integer(text):
function IsInteger(const text: String): Boolean
Usage:
Example 1: Input Validation of Integers
#include "splashkit.h"
int main(){ write_line("Welcome to the Integer Validation Checker!");
// Get the user input as a string write_line("Please enter a valid integer:"); string input = read_line();
// Check if the input is a valid integer // Loop while the user input is NOT valid (aka check for the wrong answers here) while (!is_integer(input)) { write_line("Oops! That's not a valid integer. Please try again."); // Allow the user to enter their input again write_line("Please enter a valid integer:"); input = read_line(); }
// Convert input to integer int number = convert_to_integer(input); write_line("Great! You've entered a valid integer: " + std::to_string(number));
write_line("Thank you for using the Integer Validation Checker!");
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Welcome to the Integer Validation Checker!");
// Get the user input as a stringWriteLine("Please enter a valid integer:");string input = ReadLine();
// Check if the input is a valid integer// Loop while the user input is NOT valid (aka check for the wrong answers here)while (!IsInteger(input)){ WriteLine("Oops! That's not a valid integer. Please try again."); // Allow the user to enter their input again WriteLine("Please enter a valid integer:"); input = ReadLine();}
// Convert input to integerint number = ConvertToInteger(input);WriteLine($"Great! You've entered a valid integer: {number}");
WriteLine("Thank you for using the Integer Validation Checker!");
using SplashKitSDK;
namespace IsIntegerExample{ public class Program { public static void Main() { SplashKit.WriteLine("Welcome to the Integer Validation Checker!");
// Get the user input as a string SplashKit.WriteLine("Please enter a valid integer:"); string input = SplashKit.ReadLine();
// Check if the input is a valid integer // Loop while the user input is NOT valid (aka check for the wrong answers here) while (!SplashKit.IsInteger(input)) { SplashKit.WriteLine("Oops! That's not a valid integer. Please try again."); // Allow the user to enter their input again SplashKit.WriteLine("Please enter a valid integer:"); input = SplashKit.ReadLine(); }
// Convert input to integer int number = SplashKit.ConvertToInteger(input); SplashKit.WriteLine($"Great! You've entered a valid integer: {number}");
SplashKit.WriteLine("Thank you for using the Integer Validation Checker!"); } }}
from splashkit import *
write_line("Welcome to the Integer Validation Checker!")
# Get the user input as a stringwrite_line("Please enter a valid integer:")input = read_line()
# Check if the input is a valid integer# Loop while the user input is NOT valid (aka check for the wrong answers here)while (not is_integer(input)): write_line("Oops! That's not a valid integer. Please try again.") # Allow the user to enter their input again write_line("Please enter a valid integer:") input = read_line()
# Convert input to integernumber = convert_to_integer(input)write_line(f"Great! You've entered a valid integer: {number}")
write_line("Thank you for using the Integer Validation Checker!")
Output:
Is Number
Checks if a string contains a number.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to check. |
Return Type: Boolean
Signatures:
bool is_number(const string &text)
public static bool SplashKit.IsNumber(string text);
def is_number(text):
function IsNumber(const text: String): Boolean
Usage:
Length Of
Returns the length of a string in characters.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to get the length of |
Return Type: Integer
Signatures:
int length_of(const string &text)
public static int SplashKit.LengthOf(string text);
def length_of(text):
function LengthOf(const text: String): Integer
Usage:
Example 1: How long is a string?
#include "splashkit.h"
int main(){ // Array of strings to analyse string texts[7] = {"SplashKit", "Hello", "12345", "A quick brown fox leaps high", "3.141592653589793", "hi", ""};
// Loop through each string and print its length for (int i = 0; i < 7; i++) { string text = texts[i]; int length = length_of(text); // Get the length of the string write_line("The length of '" + text + "' is:" + std::to_string(length) + " characters."); }
return 0;}
using static SplashKitSDK.SplashKit;
// Array of strings to analysestring[] texts = { "SplashKit", "Hello", "12345", "A quick brown fox leaps high", "3.141592653589793", "hi", "" };
// Loop through each string and print its lengthforeach (string text in texts){ int length = LengthOf(text); // Get the length of the string WriteLine($"The length of '{text}' is: {length} characters.");}
using SplashKitSDK;
namespace LengthOfExample{ public class Program { public static void Main() { // Array of strings to analyse string[] texts = { "SplashKit", "Hello", "12345", "A quick brown fox leaps high", "3.141592653589793", "hi", "" };
// Loop through each string and print its length foreach (string text in texts) { int length = SplashKit.LengthOf(text); // Get the length of the string SplashKit.WriteLine($"The length of '{text}' is: {length} characters."); } } }}
from splashkit import *
# Array of strings to analysetexts = ["SplashKit", "Hello", "12345", "A quick brown fox leaps high", "3.141592653589793", "hi", ""]
# Loop through each string and print its lengthfor text in texts: length = length_of(text) # Get the length of the string write_line(f"The length of '{text}' is: {length} characters.")
Output:
Replace All
Replace all occurrences of a substring in a string with another string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to search |
substr | String | The substring to find and replace |
new_text | String | The string to replace the substring with |
Return Type: String
Signatures:
string replace_all(const string &text, const string &substr, const string &new_text)
public static string SplashKit.ReplaceAll(string text, string substr, string newText);
def replace_all(text, substr, new_text):
function ReplaceAll(const text: String; const substr: String; const newText: String): String
Split
Split a string into an array of strings based on a delimiter.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to split |
delimiter | Char | The character to split the text on |
Return Type: Vector
Signatures:
vector<string> split(const string &text, char delimiter)
public static List<string> SplashKit.Split(string text, char delimiter);
def split(text, delimiter):
function Split(const text: String; delimiter: Char): ArrayOfString
To Lowercase
Return a lowercase version of the passed in string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to convert. |
Return Type: String
Signatures:
string to_lowercase(const string &text)
public static string SplashKit.ToLowercase(string text);
def to_lowercase(text):
function ToLowercase(const text: String): String
Usage:
Example 1: Convert text to lowercase
#include "splashkit.h"
int main(){ write_line("Type a phrase in ALL CAPS (SHOUT IT!):"); string input = read_line();
// Convert input to lowercase string quieted = to_lowercase(input);
write_line("Calm down... here it is in lowercase: " + quieted);
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Type a phrase in ALL CAPS (SHOUT IT!):");string input = ReadLine();
// Convert input to lowercasestring quieted = ToLowercase(input);
WriteLine("Calm down... here it is in lowercase: " + quieted);
using SplashKitSDK;
namespace ToLowercaseExample{ public class Program { public static void Main() { SplashKit.WriteLine("Type a phrase in ALL CAPS (SHOUT IT!):"); string input = SplashKit.ReadLine();
// Convert input to lowercase string quieted = SplashKit.ToLowercase(input);
SplashKit.WriteLine("Calm down... here it is in lowercase: " + quieted); } }}
from splashkit import *
write_line("Type a phrase in ALL CAPS (SHOUT IT!):")input_text = read_line()
# Convert input to lowercasequieted = to_lowercase(input_text)
write_line(f"Calm down... here it is in lowercase: {quieted}")
Output:
To Uppercase
Return a UPPERCASE version of the passed in string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The text to convert. |
Return Type: String
Signatures:
string to_uppercase(const string &text)
public static string SplashKit.ToUppercase(string text);
def to_uppercase(text):
function ToUppercase(const text: String): String
Usage:
Example 1: Case-insensitive string comparison
#include "splashkit.h"
int main(){ write("What is your favourite colour: "); string input = read_line();
// Convert input to uppercase for comparison if (to_uppercase(input) == "PURPLE") { write_line("WOO HOO Purple club!"); } else { write_line("Great colour!"); } write_line("---");
return 0;}
using static SplashKitSDK.SplashKit;
Write("What is your favourite colour: ");string input = ReadLine();
// Convert input to uppercase for comparisonif (ToUppercase(input) == "PURPLE"){ WriteLine("WOO HOO Purple club!");}else{ WriteLine("Great colour!");}WriteLine("---");
using SplashKitSDK;
namespace ToUppercaseExample{ public class Program { public static void Main() { SplashKit.Write("What is your favourite colour: "); string input = SplashKit.ReadLine();
// Convert input to uppercase for comparison if (SplashKit.ToUppercase(input) == "PURPLE") { SplashKit.WriteLine("WOO HOO Purple club!"); } else { SplashKit.WriteLine("Great colour!"); } SplashKit.WriteLine("---"); } }}
from splashkit import *
write("What is your favourite colour: ")input = read_line()
# Convert input to uppercase for comparisonif (to_uppercase(input) == "PURPLE"): write_line("WOO HOO Purple club!")else: write_line("Great colour!")write_line("---")
Output:
Example 2: Swap between upper and lower case in a string
#include "splashkit.h"
int main(){ string text = "Monkeys love bananas, but penguins prefer ice cream sundaes."; string word = ""; string result = ""; bool to_upper = true;
// Loop through each character in the string for (int i = 0; i <= length_of(text); i++) { if (i == length_of(text) || text[i] == ' ') { // Process the word (alternate between uppercase and lowercase) if (to_upper) { result += to_uppercase(word); } else { result += to_lowercase(word); }
if (i != length_of(text)) { result += " "; // Add space after word if not at end of string }
word = ""; // Reset word to_upper = !to_upper; // Alternate case for next word } else { word += text[i]; // Add character to current word } }
write_line("Original text: " + text); write_line("Modified text: " + result);
return 0;}
using static SplashKitSDK.SplashKit;
string text = "Monkeys love bananas, but penguins prefer ice cream sundaes.";string word = "";string result = "";bool toUpper = true;
// Loop through each character in the stringfor (int i = 0; i <= LengthOf(text); i++){ if (i == LengthOf(text) || text[i] == ' ') { // Process the word (alternate between uppercase and lowercase) if (toUpper) { result += ToUppercase(word); } else { result += ToLowercase(word); }
if (i != LengthOf(text)) { result += " "; // Add space after word if not at end of string }
word = ""; // Reset word toUpper = !toUpper; // Alternate case for next word } else { word += text[i]; // Add character to current word }}
WriteLine("Original text: " + text);WriteLine("Modified text: " + result);
using SplashKitSDK;
namespace ConvertToAlternateCase{ public class Program { public static void Main() { string text = "Monkeys love bananas, but penguins prefer ice cream sundaes."; string word = ""; string result = ""; bool toUpper = true;
// Loop through each character in the string for (int i = 0; i <= SplashKit.LengthOf(text); i++) { if (i == SplashKit.LengthOf(text) || text[i] == ' ') { // Process the word (alternate between uppercase and lowercase) if (toUpper) { result += SplashKit.ToUppercase(word); } else { result += SplashKit.ToLowercase(word); }
if (i != SplashKit.LengthOf(text)) { result += " "; // Add space after word if not at end of string }
word = ""; // Reset word toUpper = !toUpper; // Alternate case for next word } else { word += text[i]; // Add character to current word } }
SplashKit.WriteLine("Original text: " + text); SplashKit.WriteLine("Modified text: " + result); } }}
from splashkit import *
text = "Monkeys love bananas, but penguins prefer ice cream sundaes."word = ""result = ""to_upper = True
# Loop through each character in the stringfor i in range(len(text) + 1): if i == len(text) or text[i] == ' ': # Process the word (alternate between uppercase and lowercase) if to_upper: result += to_uppercase(word) else: result += to_lowercase(word)
if i != len(text): result += " " # Add space after word if not at end of string
word = "" # Reset word to_upper = not to_upper # Alternate case for next word else: word += text[i] # Add character to current word
write_line("Original text: " + text)write_line("Modified text: " + result)
Output:
Trim
Return a new string that removes the spaces from the start and end of the input string.
Parameters:
Name | Type | Description |
---|---|---|
text | String | The string to trim. |
Return Type: String
Signatures:
string trim(const string &text)
public static string SplashKit.Trim(string text);
def trim(text):
function Trim(const text: String): String
Usage:
Example 1: Remove whitespace from a string
#include "splashkit.h"
int main(){ string text = " Whitespace is sneaky! ";
write_line("Original string with sneaky spaces: '" + text + "'"); write_line("Let's get rid of those pesky spaces...");
// Trim spaces from the start and end string trimmed = trim(text);
write_line("Trimmed string: '" + trimmed + "'"); write_line("Aha! Much better without those sneaky spaces!");
return 0;}
using static SplashKitSDK.SplashKit;
string text = " Whitespace is sneaky! ";
WriteLine("Original string with sneaky spaces: '" + text + "'");WriteLine("Let's get rid of those pesky spaces...");
// Trim spaces from the start and endstring trimmed = Trim(text);
WriteLine("Trimmed string: '" + trimmed + "'");WriteLine("Aha! Much better without those sneaky spaces!");
using SplashKitSDK;
namespace TrimExample{ public class Program { public static void Main() { string text = " Whitespace is sneaky! ";
SplashKit.WriteLine("Original string with sneaky spaces: '" + text + "'"); SplashKit.WriteLine("Let's get rid of those pesky spaces...");
// Trim spaces from the start and end string trimmed = SplashKit.Trim(text);
SplashKit.WriteLine("Trimmed string: '" + trimmed + "'"); SplashKit.WriteLine("Aha! Much better without those sneaky spaces!"); } }}
from splashkit import *
text = " Whitespace is sneaky! "
write_line(f"Original string with sneaky spaces: '{text}'")write_line("Let's get rid of those pesky spaces...")
# Trim spaces from the start and endtrimmed = trim(text)
write_line(f"Trimmed string: '{trimmed}'")write_line("Aha! Much better without those sneaky spaces!")
Output:
Rnd
Rnd
Generates a random number between ‘min’ and max
, including ‘min’ and ‘max’.
Parameters:
Name | Type | Description |
---|---|---|
min | Integer | the Integer representing of minimum bound. |
max | Integer | the Integer representing of maximum bound. |
Return Type: Integer
Signatures:
int rnd(int min, int max)
public static int SplashKit.Rnd(int min, int max);
def rnd_range(min, max):
function Rnd(min: Integer; max: Integer): Integer
Usage:
Example 1: Random Number Generator With Range
#include "splashkit.h"
int main(){ write_line("Let's make this more interesting!");
int min_value = 1; int max_value = 0;
// Loop until a valid range is provided while (min_value >= max_value) { // Get user input for the range write_line("Please enter the minimum number:"); min_value = convert_to_integer(read_line());
write_line("Please enter the maximum number:"); max_value = convert_to_integer(read_line());
// Check if min is smaller than max if (min_value >= max_value) { write_line("Oops! The minimum value should be less than the maximum value. Let's re-enter both values."); } }
write_line("Get ready to generate a random number between " + std::to_string(min_value) + " and " + std::to_string(max_value) + "..."); write_line("Drum roll please...");
// Generate a random number in the specified range int random_number = rnd(min_value, max_value);
write_line("Your lucky number is: " + std::to_string(random_number) + "!"); write_line("How does it feel? Want to try again?");
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Let's make this more interesting!");
int minValue = 1;int maxValue = 0;
// Loop until a valid range is providedwhile (minValue >= maxValue){ // Get user input for the range WriteLine("Please enter the minimum number:"); minValue = Convert.ToInt32(ReadLine());
WriteLine("Please enter the maximum number:"); maxValue = Convert.ToInt32(ReadLine());
// Check if min is smaller than max if (minValue >= maxValue) { WriteLine("Oops! The minimum value should be less than the maximum value. Let's re-enter both values."); }}
WriteLine($"Get ready to generate a random number between {minValue} and {maxValue}...");WriteLine("Drum roll please...");
// Generate a random number in the specified rangeint randomNumber = Rnd(minValue, maxValue);
WriteLine($"Your lucky number is: {randomNumber}!");WriteLine("How does it feel? Want to try again?");
using SplashKitSDK;
namespace RndExample{ public class Program { public static void Main() { SplashKit.WriteLine("Let's make this more interesting!");
int minValue = 1; int maxValue = 0;
// Loop until a valid range is provided while (minValue >= maxValue) { // Get user input for the range SplashKit.WriteLine("Please enter the minimum number:"); minValue = Convert.ToInt32(SplashKit.ReadLine());
SplashKit.WriteLine("Please enter the maximum number:"); maxValue = Convert.ToInt32(SplashKit.ReadLine());
// Check if min is smaller than max if (minValue >= maxValue) { SplashKit.WriteLine("Oops! The minimum value should be less than the maximum value. Let's re-enter both values."); } }
SplashKit.WriteLine($"Get ready to generate a random number between {minValue} and {maxValue}..."); SplashKit.WriteLine("Drum roll please...");
// Generate a random number in the specified range int randomNumber = SplashKit.Rnd(minValue, maxValue);
SplashKit.WriteLine($"Your lucky number is: {randomNumber}!"); SplashKit.WriteLine("How does it feel? Want to try again?"); } }}
from splashkit import *
write_line("Let's make this more interesting!")
min_value = 1max_value = 0
# Loop until a valid range is providedwhile (min_value >= max_value): # Get user input for the range write_line("Please enter the minimum number:") min_value = int(read_line())
write_line("Please enter the maximum number:") max_value = int(read_line())
# Validate if min is smaller than max if min_value < max_value: break else: write_line("Oops! The minimum value should be less than the maximum value. Let's re-enter both values.")
write_line(f"Get ready to generate a random number between {min_value} and {max_value}...")write_line("Drum roll please...")
# Generate a random number in the specified rangerandom_number = rnd_range(min_value, max_value)
write_line(f"Your lucky number is: {random_number}!")write_line("How does it feel? Want to try again?")
Output:
Rnd
Generates a random number between 0 and 1
Return Type: Float
Signatures:
float rnd()
public static float SplashKit.Rnd();
def rnd():
function Rnd(): Single
Usage:
Example 1: Coin Flip
#include "splashkit.h"
int main(){ write_line(""); write_line("Let's simulate a Coin Flip!"); write_line(""); write_line("Flipping coin ..."); delay(1500); write_line("");
float random = 0.5F;
// Add extra "randomness" for (int i = 0; i < 100; i++) { random = rnd(); }
// 50% chance of heads or tails if (random < 0.5) { write_line("Heads!"); } else { write_line("Tails!"); } write_line("");
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("");WriteLine("Let's simulate a Coin Flip!");WriteLine("");WriteLine("Flipping coin ...");Delay(1500);WriteLine("");
float random = 0.5F;
// Add extra "randomness"for (int i = 0; i < 100; i++){ random = Rnd();}
// 50% chance of heads or tailsif (random < 0.5){ WriteLine("Heads!");}else{ WriteLine("Tails!");}WriteLine("");
using SplashKitSDK;
namespace RndExample{ public class Program { public static void Main() { SplashKit.WriteLine("Let's simulate a Coin Flip!"); SplashKit.WriteLine(""); SplashKit.WriteLine("Flipping coin ..."); SplashKit.Delay(1500); SplashKit.WriteLine("");
float random = 0.5F;
// Add extra "randomness" for (int i = 0; i < 100; i++) { random = SplashKit.Rnd(); }
// 50% chance of heads or tails if (random < 0.5) { SplashKit.WriteLine("Heads!"); } else { SplashKit.WriteLine("Tails!"); } SplashKit.WriteLine(""); } }}
from splashkit import *
write_line("")write_line("Let's simulate a Coin Flip!")write_line("")write_line("Flipping coin ...")delay(1500)write_line("")
random = 0.5
# Add extra "randomness"for _ in range(100): random = rnd()
# 50% chance of heads or tailsif (random < 0.5): write_line("Heads!")else: write_line("Tails!")write_line("")
Output:
Example 2: Magic 8-Ball
#include "splashkit.h"
int main(){ // Write a terminal welcome message and instructions write_line("Welcome to the Magic 8-Ball!"); write_line("Ask a question, and let the universe decide your fate..."); write_line("Choose a question by typing the number:"); write_line("1. Will I have a good week?"); write_line("2. Is it my lucky day?"); write_line("3. Should I take that risk?"); write_line("4. Will I find what I'm looking for?");
write_line("Your choice (1-4): "); int choice = convert_to_integer(read_line());
write_line("\nShaking the Magic 8-Ball..."); delay(2000); // Add suspense
// Generate a random float and determine the response float random_value = rnd(); write_line("The universe whispers...");
if (random_value < 0.5) { // Less than 0.5 responses switch (choice) { case 1: write_line("\"Not likely, but keep your head up.\""); break; case 2: write_line("\"The odds aren't in your favor, but miracles happen.\""); break; case 3: write_line("\"It's better to wait and see.\""); break; case 4: write_line("\"Keep searching. It's not your time yet.\""); break; default: write_line("\"Hmm... the universe is confused by your question.\""); break; } } else { // Greater than or equal to 0.5 responses switch (choice) { case 1: write_line("\"Yes! This week is yours to conquer.\""); break; case 2: write_line("\"Absolutely, luck is on your side!\""); break; case 3: write_line("\"Go for it! Fortune favors the bold.\""); break; case 4: write_line("\"Yes, you'll find it sooner than you think.\""); break; default: write_line("\"Hmm... the universe is confused by your question.\""); break; } }
write_line("\nThe Magic 8-Ball has spoken. Have a great day!");}
using static SplashKitSDK.SplashKit;
// Write a terminal welcome message and instructionsWriteLine("Welcome to the Magic 8-Ball!");WriteLine("Ask a question, and let the universe decide your fate...");WriteLine("Choose a question by typing the number:");WriteLine("1. Will I have a good week?");WriteLine("2. Is it my lucky day?");WriteLine("3. Should I take that risk?");WriteLine("4. Will I find what I'm looking for?");
WriteLine("Your choice (1-4): ");int choice = ConvertToInteger(ReadLine());
WriteLine("\nShaking the Magic 8-Ball...");Delay(2000); // Add suspense
// Generate a random float and determine the responsefloat randomValue = Rnd();WriteLine("The universe whispers...");
if (randomValue < 0.5){ // Less than 0.5 responses switch (choice) { case 1: WriteLine("\"Not likely, but keep your head up.\""); break; case 2: WriteLine("\"The odds aren't in your favor, but miracles happen.\""); break; case 3: WriteLine("\"It's better to wait and see.\""); break; case 4: WriteLine("\"Keep searching. It's not your time yet.\""); break; default: WriteLine("\"Hmm... the universe is confused by your question.\""); break; }}else{ // Greater than or equal to 0.5 responses switch (choice) { case 1: WriteLine("\"Yes! This week is yours to conquer.\""); break; case 2: WriteLine("\"Absolutely, luck is on your side!\""); break; case 3: WriteLine("\"Go for it! Fortune favors the bold.\""); break; case 4: WriteLine("\"Yes, you'll find it sooner than you think.\""); break; default: WriteLine("\"Hmm... the universe is confused by your question.\""); break; }}
WriteLine("\nThe Magic 8-Ball has spoken. Have a great day!");
using SplashKitSDK;
namespace RndExample{ public class Program { public static void Main() { // Write a terminal welcome message and instructions SplashKit.WriteLine("Welcome to the Magic 8-Ball!"); SplashKit.WriteLine("Ask a question, and let the universe decide your fate..."); SplashKit.WriteLine("Choose a question by typing the number:"); SplashKit.WriteLine("1. Will I have a good week?"); SplashKit.WriteLine("2. Is it my lucky day?"); SplashKit.WriteLine("3. Should I take that risk?"); SplashKit.WriteLine("4. Will I find what I'm looking for?");
SplashKit.WriteLine("Your choice (1-4): "); int choice = SplashKit.ConvertToInteger(SplashKit.ReadLine());
SplashKit.WriteLine("\nShaking the Magic 8-Ball..."); SplashKit.Delay(2000); // Add suspense
// Generate a random float and determine the response float randomValue = SplashKit.Rnd(); SplashKit.WriteLine("The universe whispers...");
if (randomValue < 0.5) { // Less than 0.5 responses switch (choice) { case 1: SplashKit.WriteLine("\"Not likely, but keep your head up.\""); break; case 2: SplashKit.WriteLine("\"The odds aren't in your favor, but miracles happen.\""); break; case 3: SplashKit.WriteLine("\"It's better to wait and see.\""); break; case 4: SplashKit.WriteLine("\"Keep searching. It's not your time yet.\""); break; default: SplashKit.WriteLine("\"Hmm... the universe is confused by your question.\""); break; } } else { // Greater than or equal to 0.5 responses switch (choice) { case 1: SplashKit.WriteLine("\"Yes! This week is yours to conquer.\""); break; case 2: SplashKit.WriteLine("\"Absolutely, luck is on your side!\""); break; case 3: SplashKit.WriteLine("\"Go for it! Fortune favors the bold.\""); break; case 4: SplashKit.WriteLine("\"Yes, you'll find it sooner than you think.\""); break; default: SplashKit.WriteLine("\"Hmm... the universe is confused by your question.\""); break; } }
SplashKit.WriteLine("\nThe Magic 8-Ball has spoken. Have a great day!"); } }}
from splashkit import *
# Write a terminal welcome message and instructionswrite_line("Welcome to the Magic 8-Ball!")write_line("Ask a question, and let the universe decide your fate...")write_line("Choose a question by typing the number:")write_line("1. Will I have a good week?")write_line("2. Is it my lucky day?")write_line("3. Should I take that risk?")write_line("4. Will I find what I'm looking for?")
write_line("Your choice (1-4): ")choice = int(read_line())
write_line("\nShaking the Magic 8-Ball...")delay(2000) # Add suspense
# Generate a random float and determine the responserandom_value = rnd()write_line("The universe whispers...")
if random_value < 0.5: # Less than 0.5 responses if choice == 1: write_line("\"Not likely, but keep your head up.\"") elif choice == 2: write_line("\"The odds aren't in your favor, but miracles happen.\"") elif choice == 3: write_line("\"It's better to wait and see.\"") elif choice == 4: write_line("\"Keep searching. It's not your time yet.\"") else: write_line("\"Hmm... the universe is confused by your question.\"")else: # Greater than or equal to 0.5 responses if choice == 1: write_line("\"Yes! This week is yours to conquer.\"") elif choice == 2: write_line("\"Absolutely, luck is on your side!\"") elif choice == 3: write_line("\"Go for it! Fortune favors the bold.\"") elif choice == 4: write_line("\"Yes, you'll find it sooner than you think.\"") else: write_line("\"Hmm... the universe is confused by your question.\"")
write_line("\nThe Magic 8-Ball has spoken. Have a great day!")
Output:
Rnd
Generates a random number between 0 and ubound
.
Parameters:
Name | Type | Description |
---|---|---|
ubound | Integer | the Integer representing the upper bound. |
Return Type: Integer
Signatures:
int rnd(int ubound)
public static int SplashKit.Rnd(int ubound);
def rnd_int(ubound):
function Rnd(ubound: Integer): Integer
Usage:
Example 1: Random Number Generator
#include "splashkit.h"
int main(){ write_line("Get ready to generate a random number up to 1000..."); write_line("Drum roll please..."); delay(2000); // Delay for 2 seconds
// Generate a random number up to the ubound int random_number = rnd(1000);
write_line("Your lucky number is: " + std::to_string(random_number) + "!!"); write_line("Feeling lucky? Maybe it's time to play the lottery!");
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Get ready to generate a random number up to 1000...");WriteLine("Drum roll please...");Delay(2000); // Delay for 2 seconds
// Generate a random number up to the uboundint randomNumber = Rnd(1000);
WriteLine($"Your lucky number is: {randomNumber}!!");WriteLine("Feeling lucky? Maybe it's time to play the lottery!");
using SplashKitSDK;
namespace RndExample{ public class Program { public static void Main() { SplashKit.WriteLine("Get ready to generate a random number up to 1000..."); SplashKit.WriteLine("Drum roll please..."); SplashKit.Delay(2000); // Delay for 2 seconds
// Generate a random number up to the ubound int randomNumber = SplashKit.Rnd(1000);
SplashKit.WriteLine($"Your lucky number is: {randomNumber}!!"); SplashKit.WriteLine("Feeling lucky? Maybe it's time to play the lottery!"); } }}
from splashkit import *
write_line("Get ready to generate a random number up to 1000...")write_line("Drum roll please...")delay(2000) # Delay for 2 seconds
# Generate a random number up to the uboundrandom_number = rnd_int(1000)
write_line(f"Your lucky number is: {random_number}")write_line("Feeling lucky? Maybe it's time to play the lottery!")
Output:
Current Ticks
Gets the number of milliseconds that have passed since the program was started.
Return Type: Unsigned Integer
Signatures:
unsigned int current_ticks()
public static uint SplashKit.CurrentTicks();
def current_ticks():
function CurrentTicks(): Cardinal
Usage:
Example 1: How many ticks?
Note: The ‘tick’ numbers may vary slightly on different machines.
#include "splashkit.h"
int main(){ // Get the ticks before delay unsigned int ticks_before = current_ticks(); write_line("Starting tick capture..."); write_line("Ticks before any delay: " + std::to_string(ticks_before));
// Delay for 1 second (1000 milliseconds) and capture ticks delay(1000); unsigned int ticks_after_1s = current_ticks(); write_line("Ticks after 1 second: " + std::to_string(ticks_after_1s));
// Delay for 2 more seconds (2000 milliseconds) and capture ticks delay(2000); unsigned int ticks_after_2s = current_ticks(); write_line("Ticks after 2 more seconds (3 seconds total): " + std::to_string(ticks_after_2s));
// Delay for 4 more seconds (4000 milliseconds) and capture ticks delay(4000); unsigned int ticks_after_4s = current_ticks(); write_line("Ticks after 4 more seconds (7 seconds total): " + std::to_string(ticks_after_4s));
// Show the difference in ticks at each capture point unsigned int diff_1s = ticks_after_1s - ticks_before; unsigned int diff_2s = ticks_after_2s - ticks_after_1s; unsigned int diff_4s = ticks_after_4s - ticks_after_2s;
write_line("Ticks passed in the first second: " + std::to_string(diff_1s)); write_line("Ticks passed in the next 2 seconds: " + std::to_string(diff_2s)); write_line("Ticks passed in the final 4 seconds: " + std::to_string(diff_4s));
return 0;}
using static SplashKitSDK.SplashKit;
WriteLine("Starting tick capture...");
// Get the ticks before delayuint ticksBefore = CurrentTicks();WriteLine("Ticks before any delay: " + ticksBefore);
// Delay for 1 second (1000 milliseconds) and capture ticksDelay(1000);uint ticksAfter1s = CurrentTicks();WriteLine("Ticks after 1 second: " + ticksAfter1s);
// Delay for 2 more seconds (2000 milliseconds) and capture ticksDelay(2000);uint ticksAfter2s = CurrentTicks();WriteLine("Ticks after 2 more seconds (3 seconds total): " + ticksAfter2s);
// Delay for 4 more seconds (4000 milliseconds) and capture ticksDelay(4000);uint ticksAfter4s = CurrentTicks();WriteLine("Ticks after 4 more seconds (7 seconds total): " + ticksAfter4s);
// Show the difference in ticks at each capture pointuint diff1s = ticksAfter1s - ticksBefore;uint diff2s = ticksAfter2s - ticksAfter1s;uint diff4s = ticksAfter4s - ticksAfter2s;
WriteLine("Ticks passed in the first second: " + diff1s);WriteLine("Ticks passed in the next 2 seconds: " + diff2s);WriteLine("Ticks passed in the final 4 seconds: " + diff4s);
using SplashKitSDK;
namespace CurrentTicksExample{ public class Program { public static void Main() { SplashKit.WriteLine("Starting tick capture...");
// Get the ticks before delay uint ticksBefore = SplashKit.CurrentTicks(); SplashKit.WriteLine("Ticks before any delay: " + ticksBefore);
// Delay for 1 second (1000 milliseconds) and capture ticks SplashKit.Delay(1000); uint ticksAfter1s = SplashKit.CurrentTicks(); SplashKit.WriteLine("Ticks after 1 second: " + ticksAfter1s);
// Delay for 2 more seconds (2000 milliseconds) and capture ticks SplashKit.Delay(2000); uint ticksAfter2s = SplashKit.CurrentTicks(); SplashKit.WriteLine("Ticks after 2 more seconds (3 seconds total): " + ticksAfter2s);
// Delay for 4 more seconds (4000 milliseconds) and capture ticks SplashKit.Delay(4000); uint ticksAfter4s = SplashKit.CurrentTicks(); SplashKit.WriteLine("Ticks after 4 more seconds (7 seconds total): " + ticksAfter4s);
// Show the difference in ticks at each capture point uint diff1s = ticksAfter1s - ticksBefore; uint diff2s = ticksAfter2s - ticksAfter1s; uint diff4s = ticksAfter4s - ticksAfter2s;
SplashKit.WriteLine("Ticks passed in the first second: " + diff1s); SplashKit.WriteLine("Ticks passed in the next 2 seconds: " + diff2s); SplashKit.WriteLine("Ticks passed in the final 4 seconds: " + diff4s); } }}
from splashkit import *
write_line("Starting tick capture...")
# Get the ticks before delayticks_before = current_ticks()write_line(f"Ticks before any delay: {ticks_before}")
# Delay for 1 second (1000 milliseconds) and capture ticksdelay(1000)ticks_after_1s = current_ticks()write_line(f"Ticks after 1 second: {ticks_after_1s}")
# Delay for 2 more seconds (2000 milliseconds) and capture ticksdelay(2000)ticks_after_2s = current_ticks()write_line(f"Ticks after 2 more seconds (3 seconds total): {ticks_after_2s}")
# Delay for 4 more seconds (4000 milliseconds) and capture ticksdelay(4000)ticks_after_4s = current_ticks()write_line(f"Ticks after 4 more seconds (7 seconds total): {ticks_after_4s}")
# Show the difference in ticks at each capture pointdiff_1s = ticks_after_1s - ticks_beforediff_2s = ticks_after_2s - ticks_after_1sdiff_4s = ticks_after_4s - ticks_after_2s
write_line(f"Ticks passed in the first second: {diff_1s}")write_line(f"Ticks passed in the next 2 seconds: {diff_2s}")write_line(f"Ticks passed in the final 4 seconds: {diff_4s}")
Output:
Delay
Puts the program to sleep for a specified number of milliseconds. If this is larger than 1 second, SplashKit will check to see if the user tries to quit during the delay. If the user does quit, the delay function returns without waiting.
Parameters:
Name | Type | Description |
---|---|---|
milliseconds | Integer | The number of milliseconds to wait |
Signatures:
void delay(int milliseconds)
public static void SplashKit.Delay(int milliseconds);
def delay(milliseconds):
procedure Delay(milliseconds: Integer)
Usage:
Example 1: Simulating a Conversation
#include "splashkit.h"
// Write a string to the console with a delay between each charactervoid write_with_delay(const string &text, int delay_time){ string word; for (char c : text) { if (c == ' ') { write(word + " "); word = ""; delay(delay_time); } else { word += c; } } write(word); // Output the last word if there’s no trailing space}
int main(){ write_with_delay("Hello there stranger!\n", 200); delay(600);
write_with_delay("Oh, Hi! I didn't see you there.\n", 200); delay(800);
write_with_delay("Wait, did you just whisper that? ", 200); delay(800);
write_with_delay("Come on, let's try that again... \n", 200); delay(1100);
write_with_delay("HELLO THERE!\n", 200); delay(600);
write_with_delay("Okay, okay... I felt that!", 200); delay(900);
write_with_delay(" But can you go even LOUDER?\n", 200); delay(1100);
write_with_delay("HELLOOOOOOO!\n", 200); delay(1500);
write_with_delay("Wow! That was intense. Let's cool down a bit...", 200); write_line(""); delay(2100);
write_with_delay("Why are we even shouting?\n", 200); delay(1100);
write_with_delay("Oh well, it's been fun. ", 200); delay(800);
write_with_delay(" Catch you later!", 200); write_line();}
using static SplashKitSDK.SplashKit;
// Write a string to the console with a delay between each wordstatic void WriteWithDelay(string text, int delayTime){ string[] words = text.Split(' '); foreach (string word in words) { Write(word + " "); Delay(delayTime); } Write(""); // Output the last word if there’s no trailing space}
WriteWithDelay("Hello there stranger!\n", 200);Delay(600);
WriteWithDelay("Oh, Hi! I didn't see you there.\n", 200);Delay(800);
WriteWithDelay("Wait, did you just whisper that? ", 200);Delay(800);
WriteWithDelay("Come on, let's try that again...\n", 200);Delay(1100);
WriteWithDelay("HELLO THERE!\n", 200);Delay(600);
WriteWithDelay("Okay, okay... I felt that!", 200);Delay(900);
WriteWithDelay("But can you go even LOUDER?\n", 200);Delay(1100);
WriteWithDelay("HELLOOOOOOO!\n", 200);Delay(1500);
WriteWithDelay("Wow! That was intense. Let's cool down a bit...", 200);Delay(2100);
WriteWithDelay("Why are we even shouting?\n", 200);Delay(1100);
WriteWithDelay("Oh well, it's been fun.", 200);Delay(800);
WriteWithDelay("Catch you later!", 200);WriteLine();
using SplashKitSDK;
namespace DelayExample{ public class Program { // Write a string to the console with a delay between each word public static void WriteWithDelay(string text, int delayTime) { string[] words = text.Split(' '); foreach (string word in words) { SplashKit.Write(word + " "); SplashKit.Delay(delayTime); } SplashKit.Write(""); // Output the last word if there’s no trailing space }
public static void Main() { WriteWithDelay("Hello there stranger!\n", 200); SplashKit.Delay(600);
WriteWithDelay("Oh, Hi! I didn't see you there.\n", 200); SplashKit.Delay(800);
WriteWithDelay("Wait, did you just whisper that? ", 200); SplashKit.Delay(800);
WriteWithDelay("Come on, let's try that again...\n", 200); SplashKit.Delay(1100);
WriteWithDelay("HELLO THERE!\n", 200); SplashKit.Delay(600);
WriteWithDelay("Okay, okay... I felt that!", 200); SplashKit.Delay(900);
WriteWithDelay("But can you go even LOUDER?\n", 200); SplashKit.Delay(1100);
WriteWithDelay("HELLOOOOOOO!\n", 200); SplashKit.Delay(1500);
WriteWithDelay("Wow! That was intense. Let's cool down a bit...", 200); SplashKit.Delay(2100);
WriteWithDelay("Why are we even shouting?\n", 200); SplashKit.Delay(1100);
WriteWithDelay("Oh well, it's been fun.", 200); SplashKit.Delay(800);
WriteWithDelay("Catch you later!", 200); SplashKit.WriteLine(); } }}
from splashkit import *
# Write a string to the console with a delay between each worddef write_with_delay(text, delay_time): words = text.split(' ') for word in words: write(word + " ") delay(delay_time) write("") # Output the last word if there’s no trailing space
write_with_delay("Hello there stranger!\n", 200)delay(600)
write_with_delay("Oh, Hi! I didn't see you there.\n", 200)delay(800)
write_with_delay("Wait, did you just whisper that?", 200)delay(800)
write_with_delay("Come on, let's try that again...\n", 200)delay(1100)
write_with_delay("HELLO THERE!\n", 200)delay(600)
write_with_delay("Okay, okay... I felt that!", 200)delay(900)
write_with_delay("But can you go even LOUDER?\n", 200)delay(1100)
write_with_delay("HELLOOOOOOO!\n", 200)delay(1500)
write_with_delay("Wow! That was intense. Let's cool down a bit...", 200)delay(2100)
write_with_delay("Why are we even shouting?\n", 200)delay(1100)
write_with_delay("Oh well, it's been fun.", 200)delay(800)
write_with_delay("Catch you later!", 200)write_line()
Output:
Display Dialog
Display a dialog to the screen with a message for the user.
Parameters:
Name | Type | Description |
---|---|---|
title | String | The title of the dialog window. |
msg | String | The message for the dialog window. |
output_font | Font | The font for the dialog text |
font_size | Integer | The size of the font for the dialog text |
Signatures:
void display_dialog(const string &title, const string &msg, font output_font, int font_size)
public static void SplashKit.DisplayDialog(string title, string msg, Font outputFont, int fontSize);
def display_dialog(title, msg, output_font, font_size):
procedure DisplayDialog(const title: String; const msg: String; outputFont: Font; fontSize: Integer)
File As String
Return a SplashKit resource of Resource Kind
with name filename
as a string.
Parameters:
Name | Type | Description |
---|---|---|
filename | String | The filename of the resource. |
kind | Resource Kind | The kind of resource. |
Return Type: String
Signatures:
string file_as_string(string filename, resource_kind kind)
public static string SplashKit.FileAsString(string filename, ResourceKind kind);
def file_as_string(filename, kind):
function FileAsString(filename: String; kind: ResourceKind): String