How can I truncate a string? For example, if I have a string containing
"Hello All" but the space reserved for this string is of 4 chars, how can I
truncate it to "Hell"? Would I need to create my own method for this or is
there an exisiting String method that does it?
Thanks 5 37537
yourStringInstance.Substring will do it.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"VM" <vo******@yahoo.com> wrote in message
news:eh**************@TK2MSFTNGP12.phx.gbl... How can I truncate a string? For example, if I have a string containing "Hello All" but the space reserved for this string is of 4 chars, how can
I truncate it to "Hell"? Would I need to create my own method for this or is there an exisiting String method that does it? Thanks
Try this,
string myStr = "Hello All"
//remove characters after 4.
myStr = myStr.Remove(4,myStr.Length-4);
--
Shak
(Houston)
"VM" <vo******@yahoo.com> wrote in message
news:eh**************@TK2MSFTNGP12.phx.gbl... How can I truncate a string? For example, if I have a string containing "Hello All" but the space reserved for this string is of 4 chars, how can
I truncate it to "Hell"? Would I need to create my own method for this or is there an exisiting String method that does it? Thanks
But string.SubString assumes that the string size I'll be extracting is less
than/equal to the string source. If I extract a substring of size 12 from a
string of 4 chars, it'll throw a runtime exception.
"John Wood" <sp**@isannoying.com> wrote in message
news:#l**************@TK2MSFTNGP10.phx.gbl... yourStringInstance.Substring will do it.
-- John Wood EMail: first name, dot, second name at priorganize.com
"VM" <vo******@yahoo.com> wrote in message news:eh**************@TK2MSFTNGP12.phx.gbl... How can I truncate a string? For example, if I have a string containing "Hello All" but the space reserved for this string is of 4 chars, how
can I truncate it to "Hell"? Would I need to create my own method for this or
is there an exisiting String method that does it? Thanks
With string.Remove I also have to check the size of the string... It's more
or less like the substring.
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl... Try this,
string myStr = "Hello All"
//remove characters after 4. myStr = myStr.Remove(4,myStr.Length-4);
-- Shak (Houston)
"VM" <vo******@yahoo.com> wrote in message news:eh**************@TK2MSFTNGP12.phx.gbl... How can I truncate a string? For example, if I have a string containing "Hello All" but the space reserved for this string is of 4 chars, how
can I truncate it to "Hell"? Would I need to create my own method for this or
is there an exisiting String method that does it? Thanks
That's correct, it requires two operations if you expect that the string may
be less than the truncated size request:
x.Substring(0, Math.Min(x.Length, size))
--
John Wood
EMail: first name, dot, last name, at priorganize.com
"VM" <vo******@yahoo.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl... But string.SubString assumes that the string size I'll be extracting is
less than/equal to the string source. If I extract a substring of size 12 from
a string of 4 chars, it'll throw a runtime exception.
"John Wood" <sp**@isannoying.com> wrote in message news:#l**************@TK2MSFTNGP10.phx.gbl... yourStringInstance.Substring will do it.
-- John Wood EMail: first name, dot, second name at priorganize.com
"VM" <vo******@yahoo.com> wrote in message news:eh**************@TK2MSFTNGP12.phx.gbl... How can I truncate a string? For example, if I have a string
containing "Hello All" but the space reserved for this string is of 4 chars, how can I truncate it to "Hell"? Would I need to create my own method for this
or is there an exisiting String method that does it? Thanks
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
by: Cole Shelton |
last post by:
Hi all,
I am simply trying to do a transform to a base 64 string and back, but for
some reason, the FromBase64Transform is return less bytes than it should. I
have verified that the base64...
|
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...
|
by: Ron |
last post by:
I *just* know there's a function to do this, but I can't
find it:
I want to take the following string:
c:\winnt\23342432sss\2343243ccc\32432432423eeee\2432424cc\t...
| |
by: DotNetJunkies User |
last post by:
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the...
|
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,...
|
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...
|
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...
|
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,...
|
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,...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |