Click here to Skip to main content
15,508,644 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi!

From back end I'm fetching 250 records of contractors and storing in each separate string builder using string builder I'm append the data to the array list from these generating the file format.

Here I'm struggling with some problem that is unwanted space is displaying in between the word (or) end of the word (or) starting of the word, this issue is occurring in the every 13th record of the file and in db there is no spaces.


Kindly any one can help me.
Posted
Updated 9-Oct-12 2:39am
v8
Comments
ridoy 22-Aug-12 1:53am    
I think there is a space from where you read that data..see it carefully..if not then let us know..
Ajit Kumar Pal 9-Oct-12 7:58am    
Can you tell how are you fetching these records in string builder.
I think appending is not done correctly .
surikarthi 9-Oct-12 8:07am    
no its appending to string builder in correct way .

first i'm fetching data from db to the temporary table and from that defining to the business object(BO) using BO I'm appending to the string builder.
Ajit Kumar Pal 10-Oct-12 0:41am    
which method are you using for appending is it Append or AppendLine?
surikarthi 10-Oct-12 1:29am    
here i'm not using any properties of the string builder. using business object(i.e BO) i'm assigning to the string builder .

ex:

just I'm giving only word (i.e contractorsurname). and how I'm displaying in the text file.

StringBuilder contractorsurname = new StringBuilder(previewbo.Surname);

In above line "contractorsurname" is obj of String builder and "previewbo.Surname" this is BO its having data from db

for (int i = 0; i < 30; i++)
{
contractorsurname.Length = 30;
charsurname[i] = Convert.ToChar(contractorsurname[i]);
}

here charsurname[i] is the object of the char Arraylist, from string builder object we are assigning data to the array list and data should be 30 character so i have given limit i less than 30.


st.BaseStream.Seek(0, SeekOrigin.begin);
st.Write(charsurname, 0, contractorsurname.Length);


using above line I'm transferring data to the text file.

use Replace method.
C#
String.Replace(" ","");

Here am removing spaces in a string
 
Share this answer
 
Comments
AmitGajjar 22-Aug-12 1:17am    
correct 5+
surikarthi 22-Aug-12 1:24am    
i have used the above fn but it dnot work..
Santhosh Kumar Jayaraman 22-Aug-12 1:25am    
post your code..
surikarthi 22-Aug-12 1:25am    
my problem is while reading it doesnt show the space after displaying in .txt only it shows space in string and this is happen to only one record and remaining is displays fine...
Santhosh Kumar Jayaraman 22-Aug-12 1:26am    
I believe that record should have a actual space.
Have you tried with Trim[^], which eliminates leading and trailing whitespace.

Refer More:
Trim String in C#[^]

Have a look on detailed description on MSDN:
http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx[^]
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 22-Aug-12 1:35am    
5+
C#
strText.tostring().replace(" ","");
 
Share this answer
 
v2
C#
string txt = "                   i am a string                                ";
txt = txt.Trim();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900