Program to print the first 3 and last 3 character in string
Question : Write a program to print the first 3 and last 3 character in string ?
Common questions, You can use any programming or scripting language to print first n number or last number of characters from string.
You should be clear about the logic to extract characters from the string. If we go with C# which provides many inbuilt string functions through which you can extract as many as characters from any position.
Method 1: Simplest method is substring. Use inbuilt substring method to extract characters from string. See below code and output
Method 2: If you are not allowed to use inbuilt methods, then use loops which is available in almost all languages. I am going to use While loop but of course you can use any available loop to get work done.
See below code written in .net core using c#
There are many other techniques through which you can get this work done.
Please provide your feedback through comments below and let me know if you want to know more.
Common questions, You can use any programming or scripting language to print first n number or last number of characters from string.
You should be clear about the logic to extract characters from the string. If we go with C# which provides many inbuilt string functions through which you can extract as many as characters from any position.
Method 1: Simplest method is substring. Use inbuilt substring method to extract characters from string. See below code and output
Method 2: If you are not allowed to use inbuilt methods, then use loops which is available in almost all languages. I am going to use While loop but of course you can use any available loop to get work done.
See below code written in .net core using c#
There are many other techniques through which you can get this work done.
Please provide your feedback through comments below and let me know if you want to know more.
Comments
Post a Comment
Thanks for your valuable feedbacks.Keep visiting the blog...