sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
cmdolcet69's Avatar

Trim Function


Question posted by: cmdolcet69 (Guest) on August 27th, 2008 02:05 PM
How do I setup a string command to trim the length of the string -1

I need to get ride of the last character in my string
9 Answers Posted
EricW's Avatar
Guest - n/a Posts
#2: Re: Trim Function

dim strText as string

strText = "abcdefgh"
strText = mid(strText,1,strText.length-1)



"cmdolcet69" <colin_dolcetti@hotmail.comschreef in bericht
news:67691624-281a-408e-8945-38c3b63a0a02@z66g2000hsc.googlegroups.com...
Quote:
Originally Posted by
How do I setup a string command to trim the length of the string -1
>
I need to get ride of the last character in my string



zacks@construction-imaging.com's Avatar
zacks@construction-imaging.com August 27th, 2008 03:15 PM
Guest - n/a Posts
#3: Re: Trim Function

On Aug 27, 9:00*am, "EricW" <iem...@home.comwrote:
Quote:
Originally Posted by
dim strText as string
>
strText = "abcdefgh"
strText = mid(strText,1,strText.length-1)
>
"cmdolcet69" <colin_dolce...@hotmail.comschreef in berichtnews:67691624-281a-408e-8945-38c3b63a0a02@z66g2000hsc.googlegroups.com...
>
>
>
Quote:
Originally Posted by
How do I setup a string command to trim the length of the string -1

>
Quote:
Originally Posted by
I need to get ride of the last character in my string


Why not do it the .NET way?

newString = oldString.SubString(0, oldString.Length - 1)
Chris Dunaway's Avatar
Guest - n/a Posts
#4: Re: Trim Function

On Aug 27, 7:55 am, cmdolcet69 <colin_dolce...@hotmail.comwrote:
Quote:
Originally Posted by
How do I setup a string command to trim the length of the string -1
>
I need to get ride of the last character in my string


Dim strText As String = "ABCDEFGHX"

strText = strText.Remove(strText.Length - 1)

OR

strText = strText.Substring(0, strText.Length - 1)

Chris
Andrew Morton's Avatar
Guest - n/a Posts
#5: Re: Trim Function

Join Bytes! wrote:
Quote:
Originally Posted by
Why not do it the .NET way?
>
newString = oldString.SubString(0, oldString.Length - 1)


Surely that should be

If oldString IsNot Nothing AndAlso oldString.Length>1 Then
newString = oldString.SubString(0, oldString.Length - 1)
Else
newString=String.Empty
End If

?

Or, using VB,

newString=String.Left(oldString, Len(oldString)-1)

Andrew


Michel Posseth  [MCP]'s Avatar
Michel Posseth [MCP] August 27th, 2008 09:55 PM
Guest - n/a Posts
#6: Re: Trim Function

Andrew,,,

or

Dim NewString as string = string.empty

If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then
newString = oldString.SubString(0, oldString.Length - 1)
end if

And this is exactly why the VB functions ( framework shortcuts ) are so
handy :-)


regards

Michel







"Andrew Morton" <akm@in-press.co.uk.invalidschreef in bericht
news:6hl683Fmq1luU1@mid.individual.net...
Quote:
Originally Posted by
Join Bytes! wrote:
Quote:
Originally Posted by
>Why not do it the .NET way?
>>
>newString = oldString.SubString(0, oldString.Length - 1)

>
Surely that should be
>
If oldString IsNot Nothing AndAlso oldString.Length>1 Then
newString = oldString.SubString(0, oldString.Length - 1)
Else
newString=String.Empty
End If
>
?
>
Or, using VB,
>
newString=String.Left(oldString, Len(oldString)-1)
>
Andrew
>



James Hahn's Avatar
Guest - n/a Posts
#7: Re: Trim Function

Already explained in your other post. Please don't start a new thread for
the same query.

"cmdolcet69" <colin_dolcetti@hotmail.comwrote in message
news:67691624-281a-408e-8945-38c3b63a0a02@z66g2000hsc.googlegroups.com...
Quote:
Originally Posted by
How do I setup a string command to trim the length of the string -1
>
I need to get ride of the last character in my string


Chris Dunaway's Avatar
Guest - n/a Posts
#8: Re: Trim Function

On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
Quote:
Originally Posted by
If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then


Isn't the check for the length of the string here, unnecessary? If
the call to IsNullOrEmpty returns False, then by definition, it's
length must be at least 1.

Chris
Michel Posseth  [MCP]'s Avatar
Michel Posseth [MCP] August 28th, 2008 07:05 PM
Guest - n/a Posts
#9: Re: Trim Function

Euhmmm...... :-| yes you are right,,, forgot something


Dim NewString as string = string.empty
Dim Oldstring as string ="X"

If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then
newString = oldString.SubString(0, oldString.Length - 1)
else
NewString=OldString
end if

Cause in case of a one char string i asume the TS wants the original value
and not a empty string
in the case he wanted a empty string in this sitaution he can remove the
length and else struct











"Chris Dunaway" <dunawayc@gmail.comschreef in bericht
news:d7b7ae52-ebd7-42e8-8ccc-fe8589579d5f@m45g2000hsb.googlegroups.com...
Quote:
Originally Posted by
On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
>
Quote:
Originally Posted by
>If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then

>
Isn't the check for the length of the string here, unnecessary? If
the call to IsNullOrEmpty returns False, then by definition, it's
length must be at least 1.
>
Chris



Michel Posseth  [MCP]'s Avatar
Michel Posseth [MCP] August 28th, 2008 07:05 PM
Guest - n/a Posts
#10: Re: Trim Function

Euhmmm...... :-| yes you are right,,, forgot something


Dim NewString as string = string.empty
Dim Oldstring as string ="X"

If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then
newString = oldString.SubString(0, oldString.Length - 1)
else
NewString=OldString
end if

Cause in case of a one char string i asume the TS wants the original value
and not a empty string
in the case he wanted a empty string in this sitaution he can remove the
length and else struct











"Chris Dunaway" <dunawayc@gmail.comschreef in bericht
news:d7b7ae52-ebd7-42e8-8ccc-fe8589579d5f@m45g2000hsb.googlegroups.com...
Quote:
Originally Posted by
On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
>
Quote:
Originally Posted by
>If Not string.IsNullOrEmpty(oldString) AndAlso oldString.Length>1 then

>
Isn't the check for the length of the string here, unnecessary? If
the call to IsNullOrEmpty returns False, then by definition, it's
length must be at least 1.
>
Chris



 
Not the answer you were looking for? Post your question . . .
197,004 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,004 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors