How To Add <br> In String After Counting Particular Characters

Jan 25, 2011

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)
lastWasSpace = false;
return result;

and called function as:

string description="sdfsdfsd sdfsdf sdfsdf asdfsa dfsda safsaf sdfdf sdfs sdfsdf sdff sdf ";


And i want to check:

after every 15 characters i want to break the line.

View 3 Replies

Similar Messages:

MVC String Formatting C# - By 100 Characters Make 4 Rows Each 25 Characters?

Aug 23, 2010

I 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."

View 2 Replies

C# - Counting Occurrences Of A String In An Array And Then Removing Duplicates?

Jan 2, 2010

I am fairly new to C# programming and I am stuck on my little ASP.NET project.

My website currently examines Twitter statuses for URLs and then adds those URLs to an array, all via a regular expression pattern matching procedure. Clearly more than one person will update a with a specific URL so I do not want to list duplicates, and I want to count the number of times a particular URL is mentioned in, say, 100 tweets.

Now I have a List<String> which I can sort so that all duplicate URLs are next to each other. I was under the impression that I could compare list[i] with list[i+1] and if they match, for a counter to be added to (count++), and if they don't match, then for the URL and the count value to be added to a new array, assuming that this is the end of the duplicates.

This would remove duplicates and give me a count of the number of occurrences for each URL. At the moment, what I have is not working, and I do not know why (like I say, I am not very experienced with it all).

With the code below, assume that a JSON feed has been searched for using a keyword into srchResponse.results. The results with URLs in them get added to sList, a string List type, which contains only the URLs, not the message as a whole.

I want to put one of each URL (no duplicates), a count integer (to string) for the number of occurrences of a URL, and the username, message, and user image URL all into my jagged array called 'urls[100][]'. I have made the array 100 rows long to make sure everything can fit but generally, this is too big. Each 'row' will have 5 elements in them.

The debugger gets stuck on the line: if (sList[i] == sList[i + 1]) which is the crux of my idea, so clearly the logic is not working.

Here is sample code:

var sList = new ArrayList();
string[][] urls = new string[100][];
int ctr = 0;
int j = 1;
foreach (Result res in srchResponse.results)
string content = res.text;
string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\))+[wd:#@%/;$()~_?+-=\.&]*)";
MatchCollection matches = Regex.Matches(content, pattern);
foreach (Match match in matches)
GroupCollection groups = match.Groups;
foreach (Result res in srchResponse.results)
for (int i = 0; i < 100; i++)
if (sList[i] == sList[i + 1])
urls[ctr][0] = sList[i].ToString();
urls[ctr][1] = j.ToString();
urls[ctr][2] = res.text;
urls[ctr][3] = res.from_user;
urls[ctr][4] = res.profile_image_url;
j = 1;

The code then goes on to add each result into a StringBuilder method with the HTML.Is now edite

View 4 Replies

MVC String Formatting C# - Show 20 Characters Of 100 - Trim / Cut String?

Aug 23, 2010

I 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?

View 3 Replies

How To Remove Characters From String

Aug 16, 2010

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.

View 3 Replies

How To Fix Special Characters In String

Aug 3, 2010

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)

View 1 Replies

How To Replace Characters In String

Dec 1, 2010

i have a string and want to remove text up to the last forward slash, e.g

Should now be

How do i go about doing this?

View 2 Replies

Finding Characters In A String?

Mar 24, 2011

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?

View 7 Replies

ADO.NET :: Sort By The First N Characters Of A String?

Feb 9, 2011

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


I guess this is probably possible with a lambda expression, but I've no experience with Lambda expressions at all.

View 1 Replies

Remove Characters In A String?

May 6, 2010

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 i want to cut that to myname.

View 3 Replies

Strange Characters While Trimming String

Feb 21, 2011

using 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:


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

View 7 Replies

How To Remove Special Characters From String

Feb 20, 2011

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)...

View 2 Replies

How To Remove Characters From Middle Of String

Apr 13, 2010


UPID is always equal to 7 digits. I want to remove "UPID=(any 7 digits)".

I'd like the output to be:


Or if no query strings


View 7 Replies

ADO.NET :: Cleaning A String Input From Bad Characters

Nov 15, 2010

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?

View 5 Replies

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

View 5 Replies

Parsing A String For Special Characters In C#?

Mar 6, 2011

I am getting a string in the following format in the query string:


I want to convert it to just "Arnstung Chew". How do I do it?

Also how do I make sure that the user is not passing a script or anything harmful in the query string?

View 2 Replies

How To Insert String With Special Characters Into RTF

Jan 20, 2010

How to programatically insert string with special characters into RTF? I have rtf template I load to string and then replace all $MY_VARIABLE$ with data. Data contains special chars like 'ąęść' and the problem is that in result file these characters are replaced with '?'. It's something wrong with encoding but what?

My code looks like:

StreamReader reader = new StreamReader("template.rtf");
StringBuilder form = new StringBuilder(reader.ReadToEnd());
// here I replace variables in rtf with data
Encoding srcEncoding = new UTF8Encoding();
Encoding dstEncoding = new ASCIIEncoding();
byte[] utf = srcEncoding.GetBytes(form.ToString());
byte[] asci = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, utf);
return dstEncoding.GetString(asci);

View 1 Replies

Determine If A String Only Contains Characters From The Seven Bit Alphabet(c#)

Mar 16, 2011

I'm developing an sms application in c#. The service that I use to send a message only allows characters form the 7 bit alphabet. I'm looking for a way to check if a message only contains characters from this alphabet.

My first idea was to split the message into a character array and then loop these characters and compare them to the alphabet. But I bet there is a much better.

7 big alphabet:


View 2 Replies

C# - How To Use Strange Characters In A Query String

Apr 14, 2010

I am using silverlight / ASP .NET and C#. What if I want to do this from silverlight for instance,

// I have left out the quotes to show you literally what the characters
// are that I want to use
string password = vtakyoj#"5
string encodedPassword = HttpUtility.UrlEncode(encryptedPassword, Encoding.UTF8);
// encoded password now = vtakyoj%23%225

URI uri = new URI("");


If I debug and look at the value of uri it shows up as this (we are still inside the silverlight app),


So the %22 has become a quote for some reason.

If I then debug inside the page.aspx code (which of course is ASP .NET) the value of Request["password"] is actually this,


Which is the original value. How does that work? I would have thought that I would have to go,

HttpUtility.UrlDecode(Request["password"], Encoding.UTF8)

To get the original value.

View 2 Replies

MVC :: Display Limited Characters From String

Nov 25, 2010

I'm making a simple mvc site containing a database over the movies we have at home. When i display my movies i'd like to display "the short version" of the plot, leaving the rest to be read when you actually click on the movie to see more details about it. How can I do this? Do i write some sort of limitation in the string on the index page?

View 2 Replies

C# - How To Get ASCII For Non-numeric Characters In A Given String

Nov 12, 2010

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.

View 5 Replies

String Manipulation - Removing Last Few Characters

Feb 11, 2011

When I try to remove the last few characters of a string, I get an index out of range error. I am using the following to remove the characters from the end of the string: objJSONStringBuilder.Remove(objJSONStringBuilder.Length - 1, 6) The string has <hr /> at the end which I want to remove.

View 3 Replies

C# Remove Characters On Left Of A String Up To The #?

Jun 15, 2010

Om C# how can i remove all the characters on the left and the #?

Take this: aaaeeae#'

And make it this:'

View 2 Replies

Web Forms :: How To Split A String Using 2 Special Characters

Sep 21, 2010

I am retrieving time data from database.Its in format of HRS:Min AM. (:,'')are the special charatcters. I need to show Hrs in txtHrs,Min in txtMin,Am/PM in dropdown. How can I do this?

View 6 Replies

Getting 'too Many Characters In String Literal' In The First Line Of Function?

Nov 25, 2010

Here is my JavaScript:

<script type="text/javascript">
function onholdev(index) {
var chk = document.getElementById('<%=grdCons.Rows[' + index + '].FindControl


View 3 Replies

Copyrights 2005-15, All rights reserved