String to Title Case

Text Input
Sample
Title Case Output

String to Title Case

The tool is an online and free tool that allows you to convert a given string to title case format. It has no dependencies on any system or software, making it accessible and convenient to use. With features like clearing the input, copying the output, and having sample text, this tool provides a user-friendly interface for converting strings to title case.

Purpose and Scenario

The purpose of the tool is to convert strings to title case format. Title case is commonly used when writing titles, such as the title of a book, a song, or a movie. By using this tool, you can easily convert any string to title case without the need for any programming knowledge or software installations.

This tool is beneficial in various scenarios, including:

  • Content creation: When writing articles, blog posts, or any other types of content, you can use this tool to convert headings or titles to title case format, giving your content a professional and polished look.
  • Data processing: If you have a dataset or a list of strings that need to be converted to title case, this tool can efficiently handle the task without any system dependencies.
  • Learning: If you are new to programming and want to understand how title case conversion works, this tool provides code examples in different programming languages.

How to Use the Tool

Using the tool is straightforward. Follow the steps below to convert your strings to title case:

  1. Input the string: In the provided text box, enter or paste the string that you want to convert to title case. For example, if you input the string "string to title case", the tool will convert it to "String to Title Case".
  2. Click the Convert button: Once you have entered the desired string, click the Convert button. The tool will instantly convert the string to title case format.
  3. Copy the output: After the conversion, you can simply click the Copy button to copy the converted string to your clipboard. This allows you to easily paste the converted string wherever you need it.

Code Examples in Different Programming Languages

If you are interested in understanding how title case conversion is implemented in different programming languages, this section provides code examples and explanations for each language.

Python

def convert_to_title_case(string):
    title_case_words = []
    non_title_case_words = ['a', 'an', 'the', 'and', 'but', 'or', 'for', 'nor', 'on', 'at', 'to', 'from', 'by', 'over']

    for word in string.split():
        if word.lower() in non_title_case_words:
            title_case_words.append(word.lower())
        else:
            title_case_words.append(word.capitalize())

    return ' '.join(title_case_words)

## Example usage
input_string = 'string to title case'
output_string = convert_to_title_case(input_string)
print(output_string)

In Python, we can split the input string into individual words using the split() function. Then, we check if each word is in the list of non-title case words (articles, conjunctions, and prepositions). If it is, we convert the word to lowercase. Otherwise, we capitalize the word. Finally, we join the words back together using the join() method.

Java

public class TitleCaseConverter {
    public static String convertToTitleCase(String string) {
        StringBuilder titleCaseString = new StringBuilder();
        String[] words = string.split(" ");
        String[] nonTitleCaseWords = {"a", "an", "the", "and", "but", "or", "for", "nor", "on", "at", "to", "from", "by", "over"};

        for (String word : words) {
            if (containsIgnoreCase(nonTitleCaseWords, word)) {
                titleCaseString.append(word.toLowerCase());
            } else {
                titleCaseString.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1).toLowerCase());
            }
            titleCaseString.append(" ");
        }

        return titleCaseString.toString().trim();
    }

    private static boolean containsIgnoreCase(String[] arr, String word) {
        for (String element : arr) {
            if (element.equalsIgnoreCase(word)) {
                return true;
            }
        }
        return false;
    }

    // Example usage
    public static void main(String[] args) {
        String inputString = "string to title case";
        String outputString = convertToTitleCase(inputString);
        System.out.println(outputString);
    }
}

In Java, we split the input string into individual words using the split() method. Then, we check if each word is in the array of non-title case words. If it is, we convert the word to lowercase. Otherwise, we capitalize the first character and convert the rest of the characters to lowercase. Finally, we join the words together and trim any leading or trailing spaces.

JavaScript

function convertToTitleCase(string) {
  var titleCaseString = "";
  var words = string.toLowerCase().split(" ");
  var nonTitleCaseWords = [
    "a",
    "an",
    "the",
    "and",
    "but",
    "or",
    "for",
    "nor",
    "on",
    "at",
    "to",
    "from",
    "by",
    "over",
  ];

  for (var i = 0; i < words.length; i++) {
    var word = words[i];
    if (nonTitleCaseWords.includes(word)) {
      titleCaseString += word;
    } else {
      titleCaseString += word.charAt(0).toUpperCase() + word.slice(1);
    }
    titleCaseString += " ";
  }

  return titleCaseString.trim();
}

// Example usage
var inputString = "string to title case";
var outputString = convertToTitleCase(inputString);
console.log(outputString);

In JavaScript, we split the input string into individual words using the split() method. Then, we check if each word is in the array of non-title case words. If it is, we keep the word as it is. Otherwise, we capitalize the first character and append the rest of the word. Finally, we join the words together and trim any leading or trailing spaces.

Golang

package main

import (
    "fmt"
    "strings"
)

func convertToTitleCase(s string) string {
    titleCaseString := ""
    words := strings.Fields(strings.ToLower(s))
    nonTitleCaseWords := []string{"a", "an", "the", "and", "but", "or", "for", "nor", "on", "at", "to", "from", "by", "over"}

    for _, word := range words {
        if contains(nonTitleCaseWords, word) {
            titleCaseString += word
        } else {
            titleCaseString += strings.Title(word)
        }
        titleCaseString += " "
    }

    return strings.TrimSpace(titleCaseString)
}

func contains(arr []string, word string) bool {
    for _, element := range arr {
        if strings.EqualFold(element, word) {
            return true
        }
    }
    return false
}

// Example usage
func main() {
    inputString := "string to title case"
    outputString := convertToTitleCase(inputString)
    fmt.Println(outputString)
}

In Golang, we split the input string into individual words using the Fields() function from the strings package. Then, we check if each word is in the slice of non-title case words. If it is, we keep the word as it is. Otherwise, we convert the word to title case using Title(). Finally, we join the words together and trim any leading or trailing spaces.

Ruby

def convert_to_title_case(string)
    title_case_string = ''
    words = string.downcase.split(' ')
    non_title_case_words = ['a', 'an', 'the', 'and', 'but', 'or', 'for', 'nor', 'on', 'at', 'to', 'from', 'by', 'over']

    words.each do |word|
        if non_title_case_words.include?(word)
            title_case_string += word
        else
            title_case_string += word.capitalize
        end
        title_case_string += ' '
    end

    title_case_string.strip
end

## Example usage
input_string = 'string to title case'
output_string = convert_to_title_case(input_string)
puts output_string

In Ruby, we split the input string into individual words using the split() method. Then, we check if each word is in the array of non-title case words. If it is, we keep the word as it is. Otherwise, we capitalize the word. Finally, we join the words together and remove any leading or trailing spaces.

Frequently Asked Questions (FAQ)

Meet our more Tools