In: Computer Science
A. Describe situations in which it might be necessary to trim leading or trailing characters from string data input by the user?
B. Describe situations in which it might be necessary to pad string data or to replace portions within a string? Consider phone numbers, Social Security numbers, and address details.
C. What are other useful methods that use to manipulate a string?
A. We need to Trim leading and trailing characters from string data input by the user in the situations like entering email or some case sensitive data if we add spaces at the end or in front the value of data we entered will be changed because computers encode the values of the space and change the Unicode of entire data
B. Padding a string and replacing some portions are quite normal in string manipulation techniques like when you are entering some data into the web browser it needs to know what kind of data you are entering. When entering a phone number we need to pad it especially otherwise there will be a chance to consider it as some other number which is related to your address and Padding the letters in the right way helps the others to get most of the knowledge by seeing only.
Replacing some portions of string-like when there is two spaces afterword to word doesn't make any sense and it even looks odd to the people who are watching it so in that case we need to replace those two spaces with one space. And mostly when you are starting to write something we need to start it with Captial letter after pull stop in that case replacing helps us to Make the first letter capitalize.
C. There are lots of string manipulation techniques available now.
Here I am gonna write about some of the useful string manipulation techniques
Length: Getting the length of the string is very useful as it restricts the input of data to the maximum length we defined to the string. We can even also set the minimum length of the string.
Upper/Lower: We can make the strings all as capital and all as lower which helps the string to change all its characters to Captial letters or Lower letters. This is mostly used while taking an email address from the user even he entered email address with capital letters the system automatically converts them into small and gives access to the email.
Join: We can join the string with a letter or some other string.
index of: This is mostly used to access the position of the letter in a string. It will tells about where the character is located
Substring: This substring technique helps us to extract the substring which is some part of String.
I hope this answer Helps to you!
Feel free to comment in the comment section if you have any doubts or queries
Thank you! do upvote.