Trimming Commas From The End Of A Stringbuilder?

Jan 22, 2010

I've a string builder, and I need to convert it to a string, and then trim any commas if there are any there (I need to get rid of them because I'm building an sql query).

Here's what I'm doing:

myStringBuilder.ToString().TrimEnd(',');

Why isn't this working??? It's not trimming any commas at the end!

I'm using c# :)

View 9 Replies


Similar Messages:

AJAX :: FilteredTextBoxExtender Want To Allow Commas?

Jan 21, 2011

i am using the filtered text box extender.I want to allow commas like "," but not possible with the code below.how do i change this to make commas acceptable?

View 3 Replies

How To Read A CSV With Embedded Commas In Fields

Oct 18, 2010

I am trying to read a CSV file which has commas embedded within certain fields.

Eg.

"Joe Bloggs", "123 Bloggs Street, Bloggsville, MA, USA", "123.34", "XYZ"
"John Doe", "12 JD Avenue, MA, USA", "53.2", "QRS"

As you can see I have the same amount of fields with a differing amount of comma characters in each. I was using the comma character (',') to split my string into different fields but this gave me varied results.

I have no control over the format of the file so restrucuring it is not an option.

Is there a way where I can split the string by using the comma and maintaining the address field as a single field.

View 2 Replies

Possible To Get The CompareValidator To Accept Numbers With Commas?

Aug 31, 2010

I had been doing a type check for Double for an input field on a web page but now I need to allow commas. Can this be done using a CompareValidator or do I need to use a regex validator?

View 1 Replies

CSV Validation In C# - Making Sure Each Row Has The Same Number Of Commas

Mar 10, 2011

I wish to implement a fairly simple CSV checker in my C#/ASP.NET application - my project automatically generates CSV's from GridView's for users, but I want to be able to quickly run through each line and see if they have the same amount of commas, and throw an exception if any differences occur. So far I have this, which does work but there are some issues I'll describe soon:

int? CommaCount = null;

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
String Str = null;
//This loops through all the headerrow cells and writes them to the stringbuilder
for (int k = 0; k <= (grd.Columns.Count - 1); k++)
{
sw.Write(grd.HeaderRow.Cells[k].Text + ",");
}
sw.WriteLine(",");
//This loops through all the main rows and writes them to the stringbuilder
for (int i = 0; i <= grd.Rows.Count - 1; i++)
{
StringBuilder RowString = new StringBuilder();
for (int j = 0; j <= grd.Columns.Count - 1; j++)
{
//We'll need to strip meaningless junk such as <br /> and
Str = grd.Rows[i].Cells[j].Text.ToString().Replace("<br />", "");
if (Str == " ")
{
Str = "";
}
Str = """ + Str + """ + ",";
RowString.Append(Str);
sw.Write(Str);
}
sw.WriteLine();
//The below code block ensures that each row contains the same number of commas, which is crucial
int RowCommaCount = CheckChar(RowString.ToString(), ',');
if (CommaCount == null)
{
CommaCount = RowCommaCount;
}
else
{
if (CommaCount!= RowCommaCount)
{
throw new Exception("CSV generated is corrupt - line " + i + " has " + RowCommaCount + " commas when it should have " + CommaCount);
}
}
}
sw.Close();

And my CheckChar method:

protected static int CheckChar(string Input, char CharToCheck)
{
int Counter = 0;
foreach (char StringChar in Input)
{
if (StringChar == CharToCheck)
{
Counter++;
}
}
return Counter;
}

Now my problem is, if a cell in the grid contains a comma, my check char method will still count these as delimiters so will return an error. As you can see in the code, I wrap all the values in " characters to 'escape' them. How simple would it be to ignore commas in values in my method? I assume I'll need to rewrite the method quite a lot.

View 4 Replies

Facebox Adding Commas To Input?

Jan 8, 2010

I'm using a facebox to display a form inside a lightbox, nothing too exciting (just a couple of datepickers, some textboxes and a checkbox). However, I'm having issues with the postbacks, whenever I post back from the facebox it adds a ',' to the start of the input (so "rabbit" becomes ",rabbit") Now, I saw that there was the same issue with the modalpopup extender from the ajaxcontroltoolkit, so I assume it's a common issue.

Can anyone either explain why this is happening, or tell me how to fix it? provide a decent way of fixing this?

See attached answer for a correct solution (I fixed this eventually but didn't want to ruin the bounty question so left the answer until afterwards).

View 3 Replies

Commas Not Recognized In File Exists?

Jul 21, 2012

I have a .net aspx project done with VS 2008 using the .Net 2.xxxx framework. This ASPX application is deployed on and 4 different 2003 Server boxes. 3 are running in total beautifully. In the 4th box is my issue. I do a FILE.EXISTS conditional test looking for case file pdf's. These case numbers are structured as such 2012-C-0421,001,0008.PDF

Please note the comma's used in the path. 3 of the 4 servers in court houses recognize the path to the pdf WITH the commas in them perfectly and the FILE.EXISTS works 100%. On the fourth box (same config we THINK) the exact same FILE.EXISTS does not return a hit even though we see the document sitting in the folder via explorer. IF we remove the commas and make it 2012-C-0421001008.pdf all is fine and document is indeed discovered with the EXISTS.

WHY on this one server does the original ducument path not function. We can not ask the court houses to change the way they store their documents so I need to make this work like the other 3. Again... same version..same .net framework... same OS (2003 server)

View 4 Replies

Strange Characters While Trimming String

Feb 21, 2011

using vb.net/asp.net 2005 and sql server 2005. I'm querying the database and returning text which I am then adding to a string. I'm creating a crystal report with the text however this is not a crystal report question, its about the string data. what I"m noticing is that when I show the string on the pdf that there are some strange characters at the end of the string. I am both trimming the string and taking out null characters however the strange text shows up like this:

strangeText>
SÙÇ
TÙçy|Ü
DÙÇ
$ÛÇ
</strangeText>

does anyone know what these characters are and how to get rid of them?

View 7 Replies

WebMatrix :: Trimming A String For Concatenation

Feb 17, 2011

I have a string variable that is a concatenation of text and a variable;

var selectQueryString = "SELECT * FROM WholesaleItems WHERE ProductClass like '" + @pc + "%'" ;

This returns with a space between the variable and the percent sign breaking the LIKE selector. I cannot find any way to trim the variable result.

View 14 Replies

GridView Is Trimming Leading Spaces?

Mar 25, 2010

The GridView in ASP.NET 2.0 is trimming the leading spaces from data coming from a SQLServer database. I have yet to find a way to keep it from doing that. The data in this particular view is being edited to remove such spaces, but only upon editing the row can any leading spaces be seen, meaning, at present, each row will have to be touched. With 12,000+ rows, that's a little much.

What little I've found on Google has mainly be concerned with trimming leading spaces. Is there a way to force GridView to show the data exactly as it is in the database, leading spaces and all?

View 1 Replies

Trimming Textbox Value Before Equating Variable?

Mar 23, 2011

C#. string SearchWords; SearchWords = TextBox1.Text (need to trim its value to a maximum length of 200)

SearchWords is a parameter being called by an SQL stored procedure. TextBox1 is a multiline text box on an aspx page.

View 5 Replies

ADO.NET :: ExecuteNonQuery Trimming Return Parameter Value?

Sep 6, 2010

I am observing a rather strange behavior. I have a procedure which selects a field from a matching record and returns it. The procedure works as expected returning proper values, when I execute the procedure from Visual Studio Server Explorer tab. The procedure is

[Code]....

This is being called from the DAL as follows:

[Code]....

The problem is if @ReturnValue is EAE then cmd.Parameter[outputParameterKey].Value is giving the value "E". If @ReturnValue is "Sassyboy" it is giving "S". why this behavior?

View 1 Replies

MVC :: Security Trimming/Roles Authorization?

Feb 28, 2011

We're writing an app that has a requirement for allowing/disallowing access based on user role.In a traditional .net app of course you set the security trimming attribute in the web.config and set the nodes in the web.sitemap file and you were set.

View 2 Replies

Web Forms :: Export To CSV File - Missing All Commas?

Jun 8, 2010

I use following code to export data to csv file:

Response.AddHeader("content-disposition", "attachment;filename=UnicodeChar.csv");
Response.ContentType = "application/octet-stream";
StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.UTF8);[code]...

It works fine. Then I download the csv file to local and open it. At last, I save it. I open the csv file with notepad, I found it misses all commas.

View 15 Replies

Does Security Trimming Work With Web Forms Routing?

May 31, 2010

In my web.config I have configured a SiteMapProvider with securityTrimmingEnabled="true" and on my main master page is an asp:Menu control bound to an asp:SiteMapDataSource. In addition I have configured restricted access to all pages in a subfolder "Admin" (using another web.config in this subfolder).

If I put a sitemapNode in Web.sitemap...

<siteMapNode url="~/Admin/Default.aspx" title="Administration" description="" >

... only users in role "Admin" will have the menu item related to that siteMapNode. So this is working fine and as intended.

Now I have defined a URL route in Global.asax to map the physical file to a new URL:

System.Web.Routing.RouteTable.Routes.MapPageRoute("AdminHomeRoute",
"Administration/Home", "~/Admin/Default.aspx");

But when I use this route-URL in the SiteMap file...

<siteMapNode url="Administration/Home" title="Administration" description="" >

... it seems that security trimming does not work: The menu item is visible for all users. (Access to the page is still restricted though, so selecting the menu item by non-Admin users does not navigate to the restricted page.)

Question: Is there any setting I've missed so far to make security trimming working with URL routing in ASP.NET 4.0 Web Forms? Did I do something wrong? Is there any work-around?

View 1 Replies

C# - Data Reader Trimming The Leading Zeros?

Jan 13, 2011

I have a string coming from a stored procedure looks like '001234567'.

sqlCommand = new SqlCommand("csp_Bbp_OBN_GetBasePageList", BBConnection);
sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.Connection.Open();
// Run the SQL statement, and then get the returned rows to the DataReader.
accReader = sqlCommand.ExecuteReader();............

In my case, from the stored procedure I am returning the varchar, after executing and reading it I am getting the value to basePage.GrouNum which is a string. So, I don't see where it is trimming the leading zeros.

Example: GroupNumber in the table is : "001234567"
BasePage.GroupNum after reading from DataReader : "1234567"

But, I do not want the leading zeros being trimmed.

View 3 Replies

SQL Server :: Trimming Field Data To Set Length?

Mar 12, 2011

What function do I use to reduce all entries in a database field to a maximum length. The field is 100 characters wide and I need to chop all existing entries in the field down to 20 characters. I prefer not to redefine the field to 20 wide to lose the data and then redefine back to 100.

UPDATE CmpyInfo
SET ( ShortName to 20 characters max )
WHERE ShortName.Length > 20

View 4 Replies

Forms Data Controls :: Format A Number With Commas?

Apr 9, 2010

I have a number that is generated from a SQL query that is populated into a tablecell as follows:

[Code]....

I get the correct value in my tablecell, except the value is 15345432. I would like to format this to show 15,345,432How can I go about doing this?

View 3 Replies

AJAX :: Modal Popup Inserting Unnecessary Commas?

Sep 20, 2010

I have a textbox inside modal popup. when i write some data into the textbox and hit ok it is appending unnecessary commas. How to remove them.

View 5 Replies

ADO.NET :: Entity Framework - Stored Procedure Mapping, Excecuting SP With Float Parameters Separated By Commas

Sep 27, 2010

Im using Entity framework with POCO entity generator template + SQL Server. I have mapping to stored procedure that takes two floats as input.

After executing function from code with two doubles as parameters: 1.23 and 4.56, SQL Profiler shows:

exec storedProcedureName @arg1 = 1,23, @arg2= 4,56

This is causing an error because it looks like that stored procedure takes 4 arguments, but it should take only two and there should be dots insted of commas in these floats.

[code]....

View 3 Replies

Is Stringbuilder Datatype

Dec 2, 2010

Is StringBuilder a datatype?

View 9 Replies

StringBuilder - Get Information On Two Lines?

Jul 9, 2010

I have a message on one and I'm sending that message to another using a Session. The problem is the message come out on one line, please code

[Code]....

Output: --- Original Message ---message for the user.

Output should be:

Original Message

message from the user. How do get the info on two lines?

View 10 Replies

How To Clear A String And Stringbuilder

Jan 25, 2010

How do I delete or clear a string? Preferable delete...

So far I've tried:

myString.TrimEnd(0, myString.Length);

myString.Remove(0, myString.Length);

myString = null;

None of the above work...

Also- how do i clear a stringbuilder? Is it in the same way?

I'm using c# and working in Visual Web Developer.

View 13 Replies

C# - How To Make StringBuilder Empty Again

Jul 12, 2010

I have a loop where i create some string value based on certain conditions. I did place StringBuilder object outside of the loop and each time i have new row in loop i need to clear StringBuilder appended values for this row.

How do i clear those?

[Code]....

View 5 Replies

Display An Image Using The Stringbuilder In C#.net?

Mar 24, 2010

How to display an image using the stringbuilder in C#.net

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved