Reverse each word in a string using c#

preview_player
Показать описание
reverse, each, word, string, using, c#, linq, dot net, .net, sentence,

In this video we will discuss how to reverse each word in a string using c#. This is a common c# interview question.

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Reverse the following string
one two three four five

Output should be
eno owt eerht ruof evif

Here is the C# code that can do this
string inputString = "one two three four five";
string resultString = string.Join(" ", inputString
.Split(' ')
.Select(x =] new String(x.Reverse().ToArray())));

Console.WriteLine(resultString);

Make sure you have the following using declarations
using System;
using System.Linq;

Here is what is happening with the above code
Split the input string using a single space as the separator. Split() method returns a string array that contains each word of the input string.
Select method, constructs a new string array, by reversing each character in each word.
Join method converts the string array into a string.

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video
Рекомендации по теме
Комментарии
Автор

wow...fantastic code. Thank you very much sir. You are a great teacher

ymtan
Автор

Hi Venkat,

I am just happy with all the learning of concept till date, but i request you to upload video on programming, i mean to have strong knowledge on programming, like Array programs, String manipulation programs, rest of the programs usally asked in interview t evalvate person programming knowledge and please help to make video on how to understand call stack and debugging from scratch, it would be really help full Venkat

Thanks

srikantsuryawanshi
Автор

Good tutorials...explanation is very clear...

surendra
Автор

Can we store image in session??? This was the question which I faced in an interview

santoshbhagawat-bomblekar
Автор

I prefer to use a foreach loop. It's more readable and understandable.

drstrangelove
Автор

Thank you for your videos sir, i got job becuase of your video before 5 years. Thank you. am telling my friends to watch your videoS :). tHANKS AGAiN:). hOPE YOU WLL REPLY.

sudhanprakash
Автор

Reading the signature of C# is always a challenge to me.

conaxlearn
Автор

also, great style of indenting lines when using the LINQ Dot operators, makes the code more readable... (beast Mode)

kiBlack
Автор

Sir, what is the real usage of string reverse operations. Please give an example.

kawsartechnologies
Автор

Thank you very much, this is very helpful! :-)

Trzbne
Автор

can we use this code it is very simple also.... please describe difference between both the codes


static void Main(string[] args)
{
Console.WriteLine("Enter a sentence");
string s = Console.ReadLine();
string[] a = s.Split(' ');
Array.Reverse(a);
Console.WriteLine("after reverse your sentence you get:");
for(int i=0;i<=a.Length-1;i++)
{
Console.Write(a[i] + "" + ' ');
}
Console.ReadKey();
}

raj
Автор

Mr kudvenkat can u write the program for, how many times repeated the same words in a given statement?

Leelakrishna
Автор

i was given a project about the human resource management. there are many employees in an IT company. one of them is a programmer whose have attributes :: programming language and hava a behaviour of code, fix, and bugs. now i don't understand how to write a program for this.can you show me a sample solution for this one

aarispradhan
Автор

Sir, What is the use of Static Class?? Plz.. reply this Question and also make a video for this question ask me on interview...

RajendraSingh-ikny
Автор

Alternative method:
string inputString = "One Two Three Four Five";

var InPutArray= inputString.ToCharArray();

Array.Reverse(InPutArray);

var joinedString = string.Join("", InPutArray);

sphxcyprex
Автор

Sir if my ID is like N001, N002... and I want to print all ID once but per ID per page how to loop or what is the easy method in c# using visual studio

ahmed
Автор

Consider a string like *** string word = " Company is Great" *** Make a program that will convert the string array to be like
Great is Company Make a Video on this...

AliHassanLearnMVC
Автор

Hii sir..
Can U Give some idea for Get Multiple Computer drive info in one single Console application in single window

vishalsali
Автор

can you please explain dependcy injection in C# with examples?

vishalparikh
Автор

how we can do this same using without any built functions of c# sir please help me ?

mahipalkamanchi