Introduction
In this blog, we will learn to convert the pascal case string to the snake case string. We will use javascript language to do this program. Before learning to convert pascal to snake case string, let's learn what pascal case string and snake case string are.
Pascal case string
Pascal case string is a string in which the first word of the string is uppercase. The rest of the letter of the word needs to be lower case. The first letter of each word is capital. There are no spaces and hyphens in the rest of the string.
For example:
string-” hello javascript.”
Pascal string-”HelloJavascript”
string-” good morning”
Pascal string-” GoodMorning”
Snake case string
A snake case string is a string in which all the letters are lowercase. The words are delimited or separated by an underscore. There are no spaces between words in the snake case string
For example:
string-” hello javascript.”
Pascal string-”hello_javascript.”
string-” good morning”
Pascal string-”good_morning”
Approach to convert Pascal case string to snake case string
We will be given a pascal string, and using the javascript function, we will convert it into a snake case string.
We have used split(), join(), toLowerCase() functions to convert pascal case string to snake case string. First, we will split the given string into arrays using the split() function; then, we will join these arrays into a string with an underscore as a separator. After that, we will convert the string to lowercase using the toLowerCase() function.
Let’s see some examples:
Input: “HaveGoodDay”
Output: “have_good_day”