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.
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
Nguồn:https://wijstaanvooronzegrondrechten.org/
Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe
I have the same task but i need to ignore numbers, what to write in code to ignore numbers?
How to sort strings like this???
Alternative method:
string inputString = "One Two Three Four Five";
var InPutArray= inputString.ToCharArray();
Array.Reverse(InPutArray);
var joinedString = string.Join("", InPutArray);
Sometime you are so slow that it waste our time.
outclass man
Sir please explain how to reverse a string without reversing words, that means instead of eno owt eerht i want three two one to be displayed
print no duplication elements in array & string
very interesting
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.
what is split
Thank you very much, this is very helpful! 🙂
Hii sir..
Can U Give some idea for Get Multiple Computer drive info in one single Console application in single window
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
can you please explain dependcy injection in C# with examples?
Mr kudvenkat can u write the program for, how many times repeated the same words in a given statement?
ERROR :
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'
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();
}
Good tutorials…explanation is very clear…
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 plzzzzzzz.
Why does Split() only accept ' ' and not " " as its argument?
how to write a program that counts the number of string. the sentecne ends with dot(.). or ! mark or a question mark
somebody write this progarm
Could somebody please tell me how to reverse the order of words in given string?
Sir, What is the use of Static Class?? Plz.. reply this Question and also make a video for this question………This question ask me on interview…
Consider a string like * string word = " Company is Great" * Make a program that will convert the string array to be like
Great is Company ……Please Make a Video on this…
i am rejected for one interview in this task ……..
how we can do this same using without any built functions of c# sir please help me ?
also, great style of indenting lines when using the LINQ Dot operators, makes the code more readable… (beast Mode)
that was sexy
Nice Tutorial.
wow…fantastic code. Thank you very much sir. You are a great teacher
5 character shorter way of doing it: String.Join(" ", inpt.Split(' ').Select(x => String.Join("", x.Reverse())));
great code