Connecting Tech Pros Worldwide Forums | Help | Site Map

Trim Function

cmdolcet69
Guest
 
Posts: n/a
#1: Aug 27 '08
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

EricW
Guest
 
Posts: n/a
#2: Aug 27 '08

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:
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
Guest
 
Posts: n/a
#3: Aug 27 '08

re: Trim Function


On Aug 27, 9:00*am, "EricW" <iem...@home.comwrote:
Quote:
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:
How do I setup a string command to trim the length of the string -1
>
Quote:
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
Guest
 
Posts: n/a
#4: Aug 27 '08

re: Trim Function


On Aug 27, 7:55 am, cmdolcet69 <colin_dolce...@hotmail.comwrote:
Quote:
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
Guest
 
Posts: n/a
#5: Aug 27 '08

re: Trim Function


zacks@construction-imaging.com wrote:
Quote:
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]
Guest
 
Posts: n/a
#6: Aug 27 '08

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:
zacks@construction-imaging.com wrote:
Quote:
>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
Guest
 
Posts: n/a
#7: Aug 28 '08

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:
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
Guest
 
Posts: n/a
#8: Aug 28 '08

re: Trim Function


On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
Quote:
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]
Guest
 
Posts: n/a
#9: Aug 28 '08

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:
On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
>
Quote:
>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]
Guest
 
Posts: n/a
#10: Aug 28 '08

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:
On Aug 27, 3:43 pm, "Michel Posseth [MCP]" <M...@posseth.comwrote:
>
Quote:
>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

Closed Thread