473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

length of string

cc
Hi,

From a C# application am I writing some text in a Word.Table, in a Cell of
the Table to be more precise.

The cell has a certain width and any string written in the cell will cover
one or more lines in the cell depending on its length. In other words, it
will use wordwrapping

Now, I have to determine the amount of lines that the text will take when
written in the cell.
How can I do this ?

thnx
Chris
Mar 14 '06 #1
11 2758
where is your string coming from before you insert it into the table?
StringBuilder? String array?

need some more info/code snippet to help

Mar 14 '06 #2
Hi,

You can use Graphics.MeasureString but you need to know the font, another
problem is the wordwrapping , I bet you would have to build your own
wrapping algorith and see how many lines you get
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"cc" <cm****@yahoo.com> wrote in message
news:44***********************@news.skynet.be...
Hi,

From a C# application am I writing some text in a Word.Table, in a Cell of
the Table to be more precise.

The cell has a certain width and any string written in the cell will cover
one or more lines in the cell depending on its length. In other words, it
will use wordwrapping

Now, I have to determine the amount of lines that the text will take when
written in the cell.
How can I do this ?

thnx
Chris

Mar 14 '06 #3
cc
Hi,

it is just a string.

some code :
m_table1.Cell(3, 4).Width = 200;
m_table1.Cell(3, 4).Range.Text = "This is my test string. It's length can
vary..."

"dkode" <dk****@gmail.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...
where is your string coming from before you insert it into the table?
StringBuilder? String array?

need some more info/code snippet to help

Mar 14 '06 #4
you can do the following:

string myString = "This is my test string. It's length can vary.";

m_table1.Cell(3, 4).Width = 200;
if (myString.Length > 200) {
// do processing or break apart the string into seperate lines I.E.
string stringPart = myString.Substring(0, 200);
string stringPart2 = myString.Substring(200, 200);
}

is this what your looking for?

Mar 14 '06 #5
Hi,

I don't think this is what the OP wants, he wants to know how many rows were
used to display the string when it was drawn in the screen.

The cell width is a pixel value, where the string length is in char, of
course one char does not fit in one pixel , so there is where the thing gets
nasty :)

OP:
See my other post to how to measure a string's representation in the screen
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"dkode" <dk****@gmail.com> wrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
you can do the following:

string myString = "This is my test string. It's length can vary.";

m_table1.Cell(3, 4).Width = 200;
if (myString.Length > 200) {
// do processing or break apart the string into seperate lines I.E.
string stringPart = myString.Substring(0, 200);
string stringPart2 = myString.Substring(200, 200);
}

is this what your looking for?

Mar 14 '06 #6
> "cc" <cm****@yahoo.com> wrote in message
news:44***********************@news.skynet.be...
Hi,

From a C# application am I writing some text in a Word.Table, in a
Cell of the Table to be more precise.

The cell has a certain width and any string written in the cell will
cover one or more lines in the cell depending on its length. In
other words, it will use wordwrapping

Now, I have to determine the amount of lines that the text will take
when written in the cell.
How can I do this ?

thnx
Chris


Ignacio Machin ( .NET/ C# MVP ) wrote: Hi,

You can use Graphics.MeasureString but you need to know the font,
another problem is the wordwrapping , I bet you would have to build
your own wrapping algorith and see how many lines you get

Or give it the dimensions of the cell..

Overloads Public Function MeasureString( _
ByVal text As String, _
ByVal font As Font, _
ByVal layoutArea As SizeF _
) As SizeF

:-)
Mar 14 '06 #7
There is an overloaded .measurestring method that allows passing it the width
and returning the size which will give you the height. Divide this by the
font height and you will get the no. of lines.
--
Dennis in Houston
"dotNuttah" wrote:
"cc" <cm****@yahoo.com> wrote in message
news:44***********************@news.skynet.be...
Hi,

From a C# application am I writing some text in a Word.Table, in a
Cell of the Table to be more precise.

The cell has a certain width and any string written in the cell will
cover one or more lines in the cell depending on its length. In
other words, it will use wordwrapping

Now, I have to determine the amount of lines that the text will take
when written in the cell.
How can I do this ?

thnx
Chris

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

You can use Graphics.MeasureString but you need to know the font,
another problem is the wordwrapping , I bet you would have to build
your own wrapping algorith and see how many lines you get

Or give it the dimensions of the cell..

Overloads Public Function MeasureString( _
ByVal text As String, _
ByVal font As Font, _
ByVal layoutArea As SizeF _
) As SizeF

:-)

Mar 15 '06 #8
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
There is an overloaded .measurestring method that allows passing it the width
and returning the size which will give you the height. Divide this by the
font height and you will get the no. of lines.
--


Sure, that will work.
As long as you don't mind silly little things like line breaks in mid character.

You really need a more involved algorithm to do proper word wrapping.

Bill
Mar 15 '06 #9
Hello, Chris,

Just a thought...

Do you really need to know the number of lines before you write to the
cell? Or could you write to the cell, and then ask: "How many lines are
in the cell?"

Cheers,
Randy
cc wrote:
Hi,

From a C# application am I writing some text in a Word.Table, in a Cell of
the Table to be more precise.

The cell has a certain width and any string written in the cell will cover
one or more lines in the cell depending on its length. In other words, it
will use wordwrapping

Now, I have to determine the amount of lines that the text will take when
written in the cell.
How can I do this ?

thnx
Chris

Mar 15 '06 #10
It's really a pretty simple algorthim to break the string into multiple
strings at the line breaks then use measurestring on each substring and add
in lines for each line break. The user should be able to extrapolate from
measurestring method to this algorthim.

--
Dennis in Houston
"Bill Butler" wrote:
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
There is an overloaded .measurestring method that allows passing it the width
and returning the size which will give you the height. Divide this by the
font height and you will get the no. of lines.
--


Sure, that will work.
As long as you don't mind silly little things like line breaks in mid character.

You really need a more involved algorithm to do proper word wrapping.

Bill

Mar 15 '06 #11
cc
That might be an option...

But I'll probably have a look at the Graphics.Measuestring()

thanks to all of you !

Chris
"R. MacDonald" <sc****@NO-SP-AMcips.ca> wrote in message
news:44***********************@news.wanadoo.nl...
Hello, Chris,

Just a thought...

Do you really need to know the number of lines before you write to the
cell? Or could you write to the cell, and then ask: "How many lines are
in the cell?"

Cheers,
Randy
cc wrote:
Hi,

From a C# application am I writing some text in a Word.Table, in a Cell of the Table to be more precise.

The cell has a certain width and any string written in the cell will cover one or more lines in the cell depending on its length. In other words, it will use wordwrapping

Now, I have to determine the amount of lines that the text will take when written in the cell.
How can I do this ?

thnx
Chris

Mar 15 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John Smith | last post by:
Hi, I'm writing a library in C++ which is supposed to be used by people using C. One function I have must return a string to users which is arbitrary length. The user must be able to use this...
5
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim...
3
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length...
1
by: gane kol | last post by:
Hi I am using DES algorithm. I am getting an error message in a few cases of the querystring Error Message : Length of the data to decrypt is invalid. Error Method : System.String...
7
by: Matt | last post by:
Have below code AcctNbr give me result of 30. That is the database column length, Column stores 10 why is giving me 30 ? while(objRead.Read()) { AcctNbr = (string)objRead.ToString().Length;...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
10
by: Mavenos | last post by:
Hi Web Masters, Just wondering wether you can help us to come up with some tokenize script. My problem is wanted to display a LONG content into a short para (by giving minimum letter lenght)...
1
by: Sathyaish | last post by:
I have the following scenario: Algorithm: 3DES Cipher Mode: CBC Key Size: 128-bit Block Size: 64 bit IV: 0x0000000000000000 (an eight byte array of zeros) The results I get using .NET with...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
1
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.