diff --git a/README.md (ToLowerCase).md (ToLowerCase).md b/README.md (ToLowerCase).md (ToLowerCase).md new file mode 100644 index 00000000..a681344e --- /dev/null +++ b/README.md (ToLowerCase).md (ToLowerCase).md @@ -0,0 +1,173 @@ +# TO LowerCase + +# Introduction + The toLowerCase() function is a fundamental text-processing tool available in many programming languages. Its primary role is to convert all characters in a string to lowercase, ensuring uniformity and enabling case-insensitive operations within the text. This function serves as a building block in various software development tasks, offering consistency and ease of manipulation when handling textual data. + The toLowerCase() function is a method available in many programming languages that converts all characters in a string to lowercase. It's a fundamental operation when dealing with text data processing. +# Exploration: + This function provides a consistent and standardized way to convert text to lowercase, enabling uniformity and easing comparisons within strings. +# Overview of ToLowerCase +The toLowerCase() function, available in programming languages like JavaScript, Java, Python, and many others, is a method used to convert all the characters within a string to their lowercase equivalents. Its primary purpose is to ensure uniformity in textual data by standardizing the case of all letters to lowercase, facilitating case-insensitive operations. + +This function is especially useful when dealing with user inputs, comparisons, or any scenario where case differences should not affect the outcome. For instance, when validating email addresses or usernames, converting all characters to lowercase enables easier and more accurate checks without worrying about case variations. + +The toLowerCase() function does not alter the original string; instead, it returns a new string with all alphabetic characters converted to lowercase. It is a simple yet powerful tool for maintaining consistency in text processing and comparison operations. + + +# PYTHON Code + + +```python +def toLowerCase(s: str) -> str: + # Initialize an empty string to store the converted characters + lowercase = "" + + # Loop through each character in the input string + for char in s: + # Check if the character is uppercase + if 'A' <= char <= 'Z': + # Convert the uppercase character to lowercase using ASCII manipulation + lowercase += chr(ord(char) + 32) + else: + # If the character is not uppercase, keep it unchanged + lowercase += char + + # Return the converted string with lowercase characters + return lowercase + +# Test the function +string = "UpperCase" +print(toLowerCase(string)) + +``` + +### Output +![Alt text](../Screenshorts/TLCPY.png) + +# Explanation: + + - The toLowerCase() function takes a string s as input and returns the string with all characters converted to lowercase. + - It initializes an empty string lowercase to store the converted characters. + - It iterates through each character in the input string using a for loop. + - For each character, it checks if it is an uppercase letter by comparing it with ASCII values. The comparison 'A' <= char <= 'Z' ensures it's an uppercase letter. + - If the character is uppercase, it converts it to lowercase using ASCII manipulation. The ord() function gets the ASCII value of the character, adds 32 to it (the difference between uppercase and lowercase ASCII values), and then chr() converts the new ASCII value back to a character. + - If the character is not uppercase, it appends it unchanged to the lowercase string. + - Finally, it returns the lowercase string containing the original string with all characters converted to lowercase. + + +# JAVA Code + +```java +public class Main { + + // Function to convert a string to lowercase + // Returns the lowercase version of the input string + + public static String toLowerCase(String s) { + StringBuilder result = new StringBuilder(); + + // Iterate through each character in the input string + for (char c : s.toCharArray()) { + // Check if the character is an uppercase letter + if (c >= 'A' && c <= 'Z') { + // Convert uppercase to lowercase using ASCII values + result.append((char) (c + 32)); + } else { + // Keep non-uppercase characters unchanged + result.append(c); + } + } + + return result.toString(); + } + + public static void main(String[] args) { + // Example string + String inputString = "UpperCase"; + + // Convert the string to lowercase and print the result + System.out.println("Original: " + inputString); + System.out.println("Lowercase: " + toLowerCase(inputString)); + } +} +``` + +### Output +![Alt text](../Screenshorts/TLCJAVA.png) + +# Explanation: + + - The toLowerCase() method takes a string s as input and returns the string with all characters converted to lowercase. + - It initializes a StringBuilder named result to store the converted characters. + - It iterates through each character in the input string using a for-each loop (for (char c : s.toCharArray())). + - For each character, it checks if it is an uppercase letter by comparing it with ASCII values (c >= 'A' && c <= 'Z'). + - If the character is uppercase, it converts it to lowercase using ASCII values. It adds 32 to the character's ASCII value to perform this conversion (result.append((char) (c + 32));). + - If the character is not an uppercase letter, it appends it unchanged to the result StringBuilder. + - Finally, it returns the string representation of the result StringBuilder using result.toString(). + +# C++ code + +```c++ + +#include + +// Function to convert a string to lowercase +// Returns the lowercase version of the input string + +std::string toLowerCase(const std::string& s) { + // Initialize an empty string to store the lowercase result + std::string result = ""; + + // Iterate through each character in the input string + for (char i : s) { + // Check if the character is an uppercase letter + if (i >= 'A' && i <= 'Z') { + // Convert uppercase to lowercase using ASCII values and append to the result + result += static_cast(i + 32); + } else { + // Keep non-uppercase characters unchanged and append to the result + result += i; + } + } + + // Return the final lowercase result + return result; +} + +int main() { + // Example string + std::string inputString = "UpperCase"; + + // Print the original string + std::cout << "Original: " << inputString << std::endl; + + // Convert the string to lowercase using the function and print the result + std::cout << "Lowercase: " << toLowerCase(inputString) << std::endl; + + return 0; +} +``` + +### Output +![Alt text](../Screenshorts/TLCC++.png) + +# Explanation: + + - The toLowerCase function takes a constant reference to a string s as input and returns the string with all characters converted to lowercase. + - It initializes an empty string result to store the converted characters. + - It iterates through each character in the input string using a range-based for loop (for (char i : s)). + - For each character, it checks if it is an uppercase letter by comparing it with ASCII values (i >= 'A' && i <= 'Z'). + - If the character is uppercase, it converts it to lowercase using ASCII values. It adds 32 to the character's ASCII value to perform this conversion (result += static_cast(i + 32)). + - If the character is not an uppercase letter, it appends it unchanged to the result string. + - Finally, it returns the result string, which contains the input string with all characters converted to lowercase. + + +# Scheduling Problems: +While seemingly unrelated, the toLowerCase() function's uniformity can be analogous to scheduling problems. It ensures consistency, akin to scheduling entities in time slots without conflicts. + +# Real-time Applications: +The toLowerCase() function is utilized in various real-world scenarios, such as: + - Data Processing: Cleaning and standardizing textual data for analysis. + - Web Development: Sanitizing inputs for uniformity and consistency in web applications. + - Comparisons: Enabling case-insensitive comparisons in search operations or string matching algorithms. +# Summary: +The toLowerCase() function, available across multiple programming languages, is a fundamental tool for standardizing and manipulating text data. Its role spans from ensuring uniformity in text to aiding in comparisons and analysis, making it a crucial component in various software development tasks. diff --git a/ToLower Case.cpp b/ToLower Case.cpp new file mode 100644 index 00000000..d93f0450 --- /dev/null +++ b/ToLower Case.cpp @@ -0,0 +1,36 @@ +#include + +// Function to convert a string to lowercase +// Returns the lowercase version of the input string +std::string toLowerCase(const std::string& s) { + // Initialize an empty string to store the lowercase result + std::string result = ""; + + // Iterate through each character in the input string + for (char i : s) { + // Check if the character is an uppercase letter + if (i >= 'A' && i <= 'Z') { + // Convert uppercase to lowercase using ASCII values and append to the result + result += static_cast(i + 32); + } else { + // Keep non-uppercase characters unchanged and append to the result + result += i; + } + } + + // Return the final lowercase result + return result; +} + +int main() { + // Example string + std::string inputString = "UpperCase"; + + // Print the original string + std::cout << "Original: " << inputString << std::endl; + + // Convert the string to lowercase using the function and print the result + std::cout << "Lowercase: " << toLowerCase(inputString) << std::endl; + + return 0; +} \ No newline at end of file diff --git a/ToLower Case.java b/ToLower Case.java new file mode 100644 index 00000000..2507a8ff --- /dev/null +++ b/ToLower Case.java @@ -0,0 +1,31 @@ +public class Main { + + // Function to convert a string to lowercase + // Returns the lowercase version of the input string + public static String toLowerCase(String s) { + StringBuilder result = new StringBuilder(); + + // Iterate through each character in the input string + for (char c : s.toCharArray()) { + // Check if the character is an uppercase letter + if (c >= 'A' && c <= 'Z') { + // Convert uppercase to lowercase using ASCII values + result.append((char) (c + 32)); + } else { + // Keep non-uppercase characters unchanged + result.append(c); + } + } + + return result.toString(); + } + + public static void main(String[] args) { + // Example string + String inputString = "UpperCase"; + + // Convert the string to lowercase and print the result + System.out.println("Original: " + inputString); + System.out.println("Lowercase: " + toLowerCase(inputString)); + } +} \ No newline at end of file diff --git a/ToLower Case.py b/ToLower Case.py new file mode 100644 index 00000000..acf702b0 --- /dev/null +++ b/ToLower Case.py @@ -0,0 +1,22 @@ + +def multi_string_search(text, patterns): + result = [] + + for pattern in patterns: + # Use the built-in find method to check if the pattern is present in the text + if text.find(pattern) != -1: + result.append(pattern) + + return result + + +if __name__ == "__main__": + # Sample text and patterns + text = "This is a sample text for multi-string search." + patterns = ["sample", "search", "notfound"] + + # Perform multi-string search + result = multi_string_search(text, patterns) + + # Print the found patterns + print("Found patterns:", *result)