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
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
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)
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
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
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
>
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
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
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
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
|
|
|
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.
Top Community Contributors
|