Stripping Out Non-numeric Characters In String?
Oct 20, 2010 Im looking to strip out non-numeric characters in a string in ASP.NET C#
So i.e 40,595 p.a.
would end up with 40595
Im looking to strip out non-numeric characters in a string in ASP.NET C#
So i.e 40,595 p.a.
would end up with 40595
I will have my string as follows
String S="AB-1233-444";
From this i would like to separate AB and would like to find out the ASCII for that 2 alphabets.
There are lots of questions on how to strip html tags, but not many on functions/methods to close them.
Here's the situation. I have a 500 character Message summary ( which includes html tags ), but I only want the first 100 characters. Problem is if I truncate the message, it could be in the middle of an html tag... which messes up stuff.
Assuming the html is something like this:
<div class="bd">"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br/>
<br/>Some Dates: April 30 - May 2, 2010 <br/>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <em>Duis aute irure dolor in reprehenderit</em> in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
</p>
For more information about Lorem Ipsum doemdloe, visit: <br/>
<a href="http://www.somesite.com" title="Some Conference">Some text link</a><br/>
</div>
How would I take the first ~100 characters or so? ( Although, ideally that would be the first approximately 100 characters of "CONTENT" ( in between the html tags )
I'm assuming the best way to do this would be a recursive algorithm that keeps track of the html tags and appends any tags that would be truncated, but that may not be the best approach.
My first thoughts are using recursion to count nested tags, and when we reach 100 characters, look for the next "<" and then use recursion to write the closing html tags needed from there.
The reason for doing this is to make a short summary of existing articles without requiring the user to go back and provide summaries for all the articles. I want to keep the html formatting, if possible.
NOTE: ignore that the html isn't totally semantic. This is what I have to deal with from my WYSIWYG.
EDIT:
I added a potential solution ( that seems to work ) I figure others will run into this problem as well. I'm not sure it's the best... and it's probably not totally robust ( in fact, I know it isn't ),
I m reading non-numeric characters in Employer ID.
My Emp id should be 5 digits. The problem is, If I m having space in those 5 characters, it is throwing error.
If it has space at the last character, it is not throwing error.
Ex : 12 34 - is throwing error
1 345 - is throwing error
but 1234 - not throwing error
My code is string numString = empid;
long number1 = 0;
bool canConvert = long.TryParse(numString, out number1); [code].....
I'm looking at some site code on an XHTML doctype and from what I'm seeing the framework is ASP.net. The IDs in the HTML has a "$" in there. For example:
<img id="$ct100templateContent$SectionPanel1$ctl01$ctl02ctl00_templateContent_SectionPanel1_ctl01_ct999img" src="this.jpg"/>
From a W3C semantic point of view the "$" is not valid in an ID or Class. IDs and classes can only contain alpha numeric characters in an XHTML doctype.
Is the the "$" a ASP.net naming convention referencing a web control or template item?
How to check the textbox1 value if there is a space or numeric or any special charecters in it
View 7 RepliesI have a string with 100 characters and it is for me too long in one line. I want to make NewLine after each 25 characters. For example:
Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
I've just encountered an interesting problem in a standard BoundField in a GridView. The field is for EmployeeCode, which is purely numeric, but stored in a character column in the database. The DataFormatString="{0:00000}" attribute on the BoundField doesn't work, as I assume that format is only for numeric values.
To work around this, I had to use a TemplateField, and bind the text value using the attribute Text='<%# PadNumericString(Eval("EmployeeCode").ToString(), 5) %>'. Is there no simpler way of doing this?
i have set the type of a column in a table numeric(6,2) but when i insert a value above 9999,99 i get the error
"Arithmetic overflow error converting numeric to data type numeric."
Do you know whats wrong??
ofc thats all through visual studio for an asp site thats why im posting here
i have a string of format ( 3.7 cm - 5.4 cm ) now i want to get the to numbers in the string into two variables for comparision
View 8 RepliesI have to validate for whether the string is decimal/numeric in code behind in asp.net.
View 1 RepliesI want to show just a part of a string for example:
Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
Just a: "Lorem ipsum dolor sit amet, consetetur sadipscing..."
Which method can I use to do that?
I have a EmpID it has string datatype and values are numeric how to sort this one?
View 5 RepliesFirst of all im new to asp.net and am in the process of learning it.
Heres my problem, i am receiving this error when submitting the form: "Arithmetic overflow error converting numeric to data type numeric"
And it halts at command.ExecuteNonQuery();
Input form:
[Code]....
Code Behind:
[Code]....
Stored Procedure:
[Code]....
i have string
Dim str As String = "C#app_wiod_200"
i want to remove characters from wiod in string which one is the best string function to do this.
I've got a program that in a nutshell reads values from a SQL database and writes them to a tab-delimited text file.
The issue is that some of the values in the database have special characters (TM, dash, ellipsis, etc.) When written to the text file, the formatting is lost and they come across as junk "â„¢ or â€" etc"
When the value is viewed in the immediate window, before it is written to the txt file, everything looks fine. My guess is that this is an issue of encoding. But, I'm not real sure how to proceed, where to look, or what to look for.
Is this ASCII or UTF-8? If it's one of those how do I correct it before it's written to the text file.
Here's how I build the text file (where feedStr is a StringBuilder)
objReader = New StreamWriter(filePath)
objReader.Write(feedStr)
objReader.Close()
i have a string and want to remove text up to the last forward slash, e.g
/images/UserThumbnails/22.jpg
Should now be
22.jpg
How do i go about doing this?
I'm currently working on this application that records a users email.
I was wondering if there was a function that would read the last 7 digits of the inputted user email and store it in a variable? Is there any way to do this?
I need to be able to sort by a product title and then by a products price, which is simple but I only want the title sorted on the first 3 or 4 characters. My client wants to add the brand name to the beginning of the product title and have them automatically sorted. I can a new field in the database called brand and sort by that, but wanted to know if this is possible. I've posted what I though might work but it doesn't
[Code]....
I guess this is probably possible with a lambda expression, but I've no experience with Lambda expressions at all.
I want to display description of product in gridview, but i want to display only 15 characters on one line, I want to break it after 15 characters, I have written countchar function as follows:
public int CountChars(string value)
{
bool lastWasSpace = false;
foreach (char c in value)
{
result++;
lastWasSpace = false;
}
return result;
}
and called function as:
string description="sdfsdfsd sdfsdf sdfsdf asdfsa dfsda safsaf sdfdf sdfs sdfsdf sdff sdf ";
CountChars(description);
And i want to check:
if(result>15)
{
after every 15 characters i want to break the line.
}
I have users emails in my database and when i retrieve those usernames, i want to remove every charecter after the @ charecter in the email for example, i have myname@domain.com i want to cut that to myname.
View 3 Repliesusing 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?
i want to display values in dropdownlist using querystring[which is successfully happening] but the problem is when id passed in querystring is 7.17 then in dropdownlist it is displaying values as 7 . 1 7....but i want to display it as 7 and 17...
here is a part of the code
string imageid;
string logoid;
string id1;
string id2;
String Name;
protected void Page_Load(object sender, EventArgs e)...
string="/?UPID=1000001&One=1&Two=2"
UPID is always equal to 7 digits. I want to remove "UPID=(any 7 digits)".
I'd like the output to be:
string="/?One=1&Two=2"
Or if no query strings
string="/"
Can anyone advice of the best way to clean an input string from characters that will cause SQL Update error? For instance:
Dim sText as string = 'this is line to a break <br> before the end.'
Dim SQLString as string = "update sometable set somefield='"
& sText & "'"
Executing SQLString will fail because of the <br> it contains. how to filter out all possible characters that will cause the update query to fail?