remove white spaces in a string without using .net build in functions [Resolved]

Posted by Pavanandey under C# on 7/27/2010 | Views : 13237 | Status : [Member] | Replies : 8
remove white spaces in a string without using .net build in functions

Thanks
Pavan Kumar
Mark Answer if this fits the need



Responses

Posted by: Neeks on: 7/27/2010 [Member] Bronze | Points: 50

Up
0
Down

Resolved
You can do this way, instead of .Replace(" ", "")

string str = "";

string strInput = "Hi dear";
foreach (char c in strInput)
{
str += (c.ToString() == " " ? "" : c.ToString());
}
MessageBox.Show(str);


Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 7/27/2010 [Member] Starter

Up
0
Down
What is the scenario, can u explain?

Regards,
Raja, USA

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 7/27/2010 [Member] Bronze

Up
0
Down
my question does not need any scenario right. just need to remove white spaces in a string with out any .net built in function.

input
-------
string S = "Hi Dear";

output
-------
S = "HiDear";

got me?


Thanks
Pavan Kumar
Mark Answer if this fits the need

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 7/27/2010 [Member] Starter

Up
0
Down
You need to loop through the length of the string and find the white space. In this case also you will need to use one or other built in function.

So get the string out of computer, count one by one and see if its empty and then take out of it and them put into the computer ;)

Regards,
Raja, USA

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ambily.raj on: 7/29/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
You can remove the white space using Regular Expressions

string s = "Hello dear \n How are you?";


//Removes the space, tab and line break
string d=Regex.Replace(s,@"[\s]","");
Console.WriteLine(d);
/*
* Output is
HellodearHowareyou?
*/

// Removes the space and tab
d = Regex.Replace(s, @"[ \t\r]", "");
Console.WriteLine(d);

/*
Output is
Hellodear
Howareyou?
*/


Thanks
Ambily K K
http://ambilykk.com/

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 7/29/2010 [Member] Bronze

Up
0
Down
Hi i alreay mentioned i dont want to use any build in function right but Regex.Replace is a build in function .

HERE I DONT WANT ANY BUILD IN FUNCTIONS

Thanks
Pavan Kumar
Mark Answer if this fits the need

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 7/29/2010 [Member] Bronze

Up
0
Down
So, there is only one way that I have mentioned earlier using Loop.


Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 4/29/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

String strText="DotNet Funda";
strText=strText.Replace(" ","")

Output:DotnetFunda


Syed Shakeer Hussain

Pavanandey, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response