Reputation:
I have the following code:
Console.Writeline("[Server] Message of client received");
for (int i = 0; i < totalBytes; i++)
{
aChar = Convert.ToChar(incomingDataBuffer[i]);
Console.Write(aChar);
}
where int totalBytes = aSocket.Receive(incomingDataBuffer);
In addition to printing the message like above, I need to iterate through the message and print it again, but remove consonants. So "Hello there" would return "eoee".
If someone could give a working example that would be great. I don't know C# but I'm learning Java now.
Upvotes: 1
Views: 1615
Reputation: 28272
Add the vowels to a string and print them afterwards. Something like:
Console.Writeline("[Server] Message of client received");
string vowels = string.Empty; // start with an empty string
for (int i = 0; i < totalBytes; i++)
{
aChar = Convert.ToChar(incomingDataBuffer[i]);
Console.Write(aChar);
// if it's a vowel add it to the "vowels" string
if("aeiouAEIOU".Contains(aChar)) vowels += aChar;
}
Console.Write(vowels); // print it out
PS: note that "vowels" might be different depending on your language... you need to define what is a vowel for you (in many cases, y
would be a vowel in English, for example, or accented letters, like é
or ü
). I've simplified it to the a-e-i-o-u
case, but it might be incorrect.
Upvotes: 1
Reputation: 8214
Here's a quick example that shows how to iterate over a string and check for vowels.
// The input.
// Your question is a little unclear and I couldn't understand how you get this string...
var message = "[Server] Message of client received";
// Iterate over each character
for (int i = 0; i < message.Length; i++)
{
// Check if character is a vowel and output if it is
if ("aeiouAEIOU".IndexOf(message[i]) >= 0)
Console.Write(message[i]);
}
Input:
[Server] Message of client received
Output:
eeeaeoieeeie
Upvotes: 1