473,383 Members | 1,829 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,383 software developers and data experts.

Truncating Variables

Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?

--

Thank You,
Jason Williard

Nov 18 '05 #1
11 1440
> Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?


Are you asking how to trim a string? If so, you could do this:

dim sourceString as string
dim truncatedString as string
truncatedString = left(sourceString, 30) & "..."

-Darrel
Nov 18 '05 #2
Darrel,

This is pretty much what I wanted. However, for the appending of "(...)",
what would it take to do that to strings that are more than 30 characters,
as not all strings are more than 30 chars?

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"darrel" <no*****@hotmail.com> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?


Are you asking how to trim a string? If so, you could do this:

dim sourceString as string
dim truncatedString as string
truncatedString = left(sourceString, 30) & "..."

-Darrel

Nov 18 '05 #3
So just check to see if the string is over 30 characters. If it is not,
leave it as is, otherwise perform this transformation on it.

"Jason Williard" <ja********@gmail.com> wrote in message
news:IlVbd.396828$Fg5.141773@attbi_s53...
Darrel,

This is pretty much what I wanted. However, for the appending of "(...)",
what would it take to do that to strings that are more than 30 characters,
as not all strings are more than 30 chars?

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"darrel" <no*****@hotmail.com> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Is there a built-in function that I can use to truncate variables longer than 30 characters? Even better, is there a function that truncates and then appends "(...)" to the end?


Are you asking how to trim a string? If so, you could do this:

dim sourceString as string
dim truncatedString as string
truncatedString = left(sourceString, 30) & "..."

-Darrel


Nov 18 '05 #4
I do something like this in SQL (I subract 1 because '...' takes approx 1
character width in my font)

IF LEN(@Description) > @Width
SET @OUT = LEFT(@Description,@Width-1) + '...'
ELSE
SET @OUT = LEFT(@Description,@Width)

In VB you would want to check that your string is not already less than 30
so as not to append "..." to everything.

Greg

"darrel" <no*****@hotmail.com> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?


Are you asking how to trim a string? If so, you could do this:

dim sourceString as string
dim truncatedString as string
truncatedString = left(sourceString, 30) & "..."

-Darrel

Nov 18 '05 #5
A variable cannot be truncated.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:i5Vbd.186746$wV.143872@attbi_s54...
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?

--

Thank You,
Jason Williard

Nov 18 '05 #6
Jason Williard wrote:
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?


If you are displaying this information in a DataGrid, you might want to
consider checking out this free custom DataGrid column:
http://aspnet.4guysfromrolla.com/articles/100202-1.aspx

It is even a bit smarter - rather than just chopping the sentence off
at, say, 30 characters, is cuts it off only at word boundaries.

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #7
ouch

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
A variable cannot be truncated.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:i5Vbd.186746$wV.143872@attbi_s54...
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?

--

Thank You,
Jason Williard


Nov 18 '05 #8
Thank you for your nice comments. How about a string?

Anyways, the others who have been kind enough to answer my question helped
me solve this.

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
A variable cannot be truncated.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:i5Vbd.186746$wV.143872@attbi_s54...
Is there a built-in function that I can use to truncate variables longer
than 30 characters? Even better, is there a function that truncates and
then appends "(...)" to the end?

--

Thank You,
Jason Williard


Nov 18 '05 #9
> Thank you for your nice comments. How about a string?

As you mentioned, someone had already answered your question.

I know you don't appreciate it, but there is a method to my madness. Knowing
the difference between a variable and a string is essential to being able to
program with .Net. It might seem like semantics to you, but it's serious
business to your computer. You can't get away with that kind of thinking in
..Net. Even VB.Net is nowhere near as forgiving as ASP and VBScript. Many VB
developers are floundering because they don't even know what data types are
(never had to think about it before). Just thank your lucky stars that you
may never have to learn about pointers!

The "point" is, with VBScript and ASP, one didn't have to know much about
the objects one played with. But in .Net, it is essential. This is
real-world programming. Variables, classes, data types, fields, properties,
bits and logic are the building blocks with which you build your app. What
kind of builder will you be if you don't take the time to understand them
first? Sure, I, like everyone else, want to get down and dirty with the
code. But some homework is necessary first. The difference between a
variable and a string is the difference between a suitcase and a change of
clothes. You wouldn't want to show up for work in a suitcase one day, would
you?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:AnWbd.253251$D%.65358@attbi_s51...
Thank you for your nice comments. How about a string?

Anyways, the others who have been kind enough to answer my question helped
me solve this.

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
A variable cannot be truncated.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:i5Vbd.186746$wV.143872@attbi_s54...
Is there a built-in function that I can use to truncate variables longer than 30 characters? Even better, is there a function that truncates and then appends "(...)" to the end?

--

Thank You,
Jason Williard



Nov 18 '05 #10
Kevin,

I completely understand where you are coming from. It was a simple mistake
on my part. I know the differences between variables and strings. That
wasn't the issue and going off on a tirade about knowing what a variable is
and is not going to help in these situations. Your comments are really
quite rude and not productive at all. A better response would have been to
answer the question while also reminding me of the differences.

--

Thank You,
Jason Williard
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ej***************@TK2MSFTNGP15.phx.gbl...
Thank you for your nice comments. How about a string?


As you mentioned, someone had already answered your question.

I know you don't appreciate it, but there is a method to my madness.
Knowing
the difference between a variable and a string is essential to being able
to
program with .Net. It might seem like semantics to you, but it's serious
business to your computer. You can't get away with that kind of thinking
in
.Net. Even VB.Net is nowhere near as forgiving as ASP and VBScript. Many
VB
developers are floundering because they don't even know what data types
are
(never had to think about it before). Just thank your lucky stars that you
may never have to learn about pointers!

The "point" is, with VBScript and ASP, one didn't have to know much about
the objects one played with. But in .Net, it is essential. This is
real-world programming. Variables, classes, data types, fields,
properties,
bits and logic are the building blocks with which you build your app. What
kind of builder will you be if you don't take the time to understand them
first? Sure, I, like everyone else, want to get down and dirty with the
code. But some homework is necessary first. The difference between a
variable and a string is the difference between a suitcase and a change of
clothes. You wouldn't want to show up for work in a suitcase one day,
would
you?

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:AnWbd.253251$D%.65358@attbi_s51...
Thank you for your nice comments. How about a string?

Anyways, the others who have been kind enough to answer my question
helped
me solve this.

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
>A variable cannot be truncated.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Jason Williard" <ja********@gmail.com> wrote in message
> news:i5Vbd.186746$wV.143872@attbi_s54...
>> Is there a built-in function that I can use to truncate variables longer >> than 30 characters? Even better, is there a function that truncates and >> then appends "(...)" to the end?
>>
>> --
>>
>> Thank You,
>> Jason Williard
>>
>>
>>
>
>



Nov 18 '05 #11
Someone else had, as I mentioned previously, answered the question.

I think if you look carefully at both of my responses, you will see that
rudeness is purely your perception. And neither answer was a "tirade." That
is pure emotional characterization. My boss pays me good money for this type
of advice. You and everyone else I help every day get it for free.

--
You're welcome,

Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:S0Ybd.245874$MQ5.214550@attbi_s52...
Kevin,

I completely understand where you are coming from. It was a simple mistake on my part. I know the differences between variables and strings. That
wasn't the issue and going off on a tirade about knowing what a variable is and is not going to help in these situations. Your comments are really
quite rude and not productive at all. A better response would have been to answer the question while also reminding me of the differences.

--

Thank You,
Jason Williard
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ej***************@TK2MSFTNGP15.phx.gbl...
Thank you for your nice comments. How about a string?


As you mentioned, someone had already answered your question.

I know you don't appreciate it, but there is a method to my madness.
Knowing
the difference between a variable and a string is essential to being able to
program with .Net. It might seem like semantics to you, but it's serious
business to your computer. You can't get away with that kind of thinking
in
.Net. Even VB.Net is nowhere near as forgiving as ASP and VBScript. Many
VB
developers are floundering because they don't even know what data types
are
(never had to think about it before). Just thank your lucky stars that you may never have to learn about pointers!

The "point" is, with VBScript and ASP, one didn't have to know much about the objects one played with. But in .Net, it is essential. This is
real-world programming. Variables, classes, data types, fields,
properties,
bits and logic are the building blocks with which you build your app. What kind of builder will you be if you don't take the time to understand them first? Sure, I, like everyone else, want to get down and dirty with the
code. But some homework is necessary first. The difference between a
variable and a string is the difference between a suitcase and a change of clothes. You wouldn't want to show up for work in a suitcase one day,
would
you?

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Jason Williard" <ja********@gmail.com> wrote in message
news:AnWbd.253251$D%.65358@attbi_s51...
Thank you for your nice comments. How about a string?

Anyways, the others who have been kind enough to answer my question
helped
me solve this.

--

Thank You,
Jason Williard
Client Services
PCSafe, Inc.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
>A variable cannot be truncated.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Jason Williard" <ja********@gmail.com> wrote in message
> news:i5Vbd.186746$wV.143872@attbi_s54...
>> Is there a built-in function that I can use to truncate variables

longer
>> than 30 characters? Even better, is there a function that truncates

and
>> then appends "(...)" to the end?
>>
>> --
>>
>> Thank You,
>> Jason Williard
>>
>>
>>
>
>



Nov 18 '05 #12

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

Similar topics

4
by: qazmlp | last post by:
Can anybody comment(& suggest improvements) on the following implementation that is for truncating the character buffer contents to the desired length? Truncating char array void...
5
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any...
1
by: Jitesh Sinha | last post by:
Hi, I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal behaviour of System.Web.mail class. It was truncating the message body after 3,071 character. The code i was testing...
3
by: rangermccoy | last post by:
Hello there, What are the best php/c libraries for handling media including images, video, and music? I would like to manipulate media dfiles, including watermarking, thumbnailing,...
1
by: Daniel Wilson | last post by:
We have a stored procedure that is giving us an XML representation (using FOR XML Explicit) of a sales order. Sometimes that evaluats to quite a long string. Unfortunately, this XML string is...
1
by: sconnors | last post by:
I am currently working on an application that runs on Windows XP SP2 with .NET 2.0, Linux 2.4.19-16mdkenterprise and Solaris 5.9. The language is C++. When I compare the output numbers, Windows...
21
by: Jenn | last post by:
I have a memo field in a report that is truncating at 255 characters. I've tried the following w/no success: 1. Grow/Shrink option is yes. 2. "Group By" changed to "first". 3. "Group by" changed to...
2
by: Bre035 | last post by:
I have created a Make-table query in Microsoft Access 2003 to retrieve comments for designated records. The queries runs fine, but it doesn't pull all the text from the comments column of the DB2...
15
geolemon
by: geolemon | last post by:
I'm having a seriously Twilight Zone moment: In the code below, I'm building a SQL command into a string variable, declared at the top of my code. Then, I connect to the database and try to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.