words in strings

  • Thread starter Thread starter Aahz
  • Start date Start date
A

Aahz

Hello;

How can I count number of word in strings, and how to find out if
some word exceed number of characters (if this happen table layout is
ruined on web page).

Any clue how C# do this?

Thank you
 
How can I count number of word in strings,

Split the string on the space character...
http://msdn2.microsoft.com/en-us/library/b873y76a.aspx
and how to find out if some word exceed number of characters

Loop through the array returned by the Split method:

string strRaw = "This is a string with some words and spaces";
string[] strWords = strRaw.Split(' ');
foreach (string strWord in strWords)
{
if (strWord.Length > 10)
{
// do something
}
}
(if this happen table layout is ruined on web page).

Presumably you're using a fixed-space font? If not, counting the number of
letters won't give you a particularly accurate value for how much screen
real estate the word will occupy...
 
Aahz said:
Hello;

How can I count number of word in strings, and how to find out if
some word exceed number of characters (if this happen table layout is
ruined on web page).

Maybe you just want to set the "overflow" CSS attribute?
 
The Web isn't WSYIWYG. Most Web developers accept the fact that they do not
have absolute control (or even "very much control") over the final
appearance of their Web pages. NO matter how carefully you structure your
Web pages, CSS and whatnot, the user can always change browser settings that
will screw up your intended layout. Even if the user doesn't change browser
settings, different browsers and different versions of browsers interpret
the various Web standards differently and therefore render HTML in different
ways. Consider, for example, the Box model and the various hacks being
promoted for those Web developers who need to work around the different
browser implementations of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top