Showing posts with label trim. Show all posts
Showing posts with label trim. Show all posts

Saturday, March 31, 2012

trim

How do I trim a value that has whitespace after the last character?
ie
<Value>123456 </Value
thanks
markif you merely use Trim(value)
or myVar.Trim
--
this will assure you have no white space at either end
Hi,

TryString.Trim Method

HTH

Trim a DB field

I have this code and it works great for some of the numbers but not ther other.

<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %> with a number of 675432 the result would be 3. With a number of 75432 the result would be 2. I need them always be in the 2 spot even if my field has a 7, 6, 5, or 4 digit numbers in it.

This is trimming the ListNum field in my database down to one number. When the database field is 6 numbers long it works perfectly. If the database number is 5 numbers long it selects the last number instead of the 2nd to the last number. Is there a way to get the trim command to count the numbers from the right and not the left. So the code would look something like this.

<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 2,1) %>

Thanks for any help.Try something like this:

Dim myString as string
myString = DataSet1.FieldValue("ListNum", Container).Trim()
myString = myString.Substring(myString.Length-2, 1)
The code is a section out of much more.. Here is the code all together.

<img src="http://pics.10026.com/?src=http://photos.neg.ctimls.com/neg/photos/small/<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %>/<%# Right(DataSet1.FieldValue("ListNum", Container).Trim(), 1) %>/<%# DataSet1.FieldValue("ListNum", Container) %>a.jpg" width="100" alt="">

Because it is a piece of a code that is why I can't use something like that. Also there are many of these for one page on the site so I have to keep it as simple as possible.

Thanks

Trim array of null object

How to remove null objects from an array? When I use the split function, I end up having an empty first element. How do I remove this? Any code is welcome...
ArrayList alArray = new ArrayList();

for ( int i = 0; i < myArray.Length; ++i )
{
if ( myArray[i] != null )
alArray.Add(myArray[i]);
}


Or maybe, if you want to remove null value objects:

for ( int i = 0; i < myArrayList.Length; i++ )
{
if (myArrayList[i] == null )
myArrayList.RemoveAt[i]);
}

The ArrayList is in many ways extremely practical, as you don't have to redim the size. You just simply remove the unwanted elements.

Trim and Substring?

I have the following in a dataset --Yeild - 15 Points - (3/6) And to do a calculation I need to pull the 3 position out of the ( ) section. It also has a capability of being something like the following --Yeild - 15 Points - (10/12) instead. Any ideas on how I would go about this?
That is put into a dataset b/c of the following Dataset (which I had a lot of help on b/c I'm still lost on Cast). However I'm just curious if anyone knows How I can pull this # out thanks.
CREATE PROCEDURE dbo.sp_Goals_GetPlantGoalsReviewPage
@dotnet.itags.org.CompanyID nvarchar(2), @dotnet.itags.org.FacilityID nvarchar(2)
AS
DECLARE @dotnet.itags.org.StartMonth int, @dotnet.itags.org.EndMonth int
SELECT @dotnet.itags.org.StartMonth = StartMonth, @dotnet.itags.org.EndMonth = EndMonth FROM Period WHERE PeriodID = dbo.fn_GetCurrentPeriod(@dotnet.itags.org.CompanyID, @dotnet.itags.org.FacilityID)
DECLARE @dotnet.itags.org.Column nvarchar(1000)
DECLARE @dotnet.itags.org.i int
SET @dotnet.itags.org.i = @dotnet.itags.org.StartMonth
SET @dotnet.itags.org.Column = 'Cast(GoalMByte' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ' AS int)'
WHILE @dotnet.itags.org.i < @dotnet.itags.org.EndMonth
BEGIN
SET @dotnet.itags.org.i = @dotnet.itags.org.i + 1
SET @dotnet.itags.org.Column = @dotnet.itags.org.Column + ' + Cast(GoalMByte' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ' AS int)'
END
DECLARE @dotnet.itags.org.Query nvarchar(2000)
SET @dotnet.itags.org.Query = ('SELECT [Description] + '' - '' + Cast(Points AS nvarchar(100)) + '' Points - ('' + Cast(' + @dotnet.itags.org.Column + ' AS nvarchar(100)) +''/' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ')'' AS PlantGoals,Points ,' + @dotnet.itags.org.Column + '/' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + 'AS Fraction
FROM Goals
WHERE CompanyID = ''' + @dotnet.itags.org.CompanyID + ''' AND FacilityID = ''' + @dotnet.itags.org.FacilityID + ''' AND PeriodID = ' + Cast(dbo.fn_GetCurrentPeriod(@dotnet.itags.org.CompanyID, @dotnet.itags.org.FacilityID) AS nvarchar(100)) + ' AND GoalCategory = ''Plant''')
EXEC (@dotnet.itags.org.Query)lets say you create a string that contains the whole string from the DB
dim strAll as string = DBRecord 'Assuming output will be something like: Yeild - 15 Points - (3/6)
Now you can tokenize the string into 3 distinct parts (Yield , 15 points, and (3/6) )
dim strTokens as string() = strAll.split("-"c)
Now to reference the (3/6) portion you can:
dim strFoo as string = strTokens(2)
Now you can split, trim all you like with just that part. :)
Sweet thanks -- I'll give it a shot.
i couldn't tell from your post if the '-' character was a hyphen or a minus sign if its a minus, (ie part of the data) split based on " " the space character
worked great thanks!

trim and pure apparently whitespace strings

has anyone encountered an apparently pure whitespace string (debug mode
mouse-over) that when TRIM'd does not result in a null-string ?

how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...

The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)

actually, i found this very useful function for discovering hidden
characters in a string:

Uri.HexEscape()

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> > has anyone encountered an apparently pure whitespace string (debug mode
> > mouse-over) that when TRIM'd does not result in a null-string ?
> > how to determine any special characters that may be present in the
string
> > ?

trim and pure apparently whitespace strings

has anyone encountered an apparently pure whitespace string (debug mode
mouse-over) that when TRIM'd does not result in a null-string ?
how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...
The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
>
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)
actually, i found this very useful function for discovering hidden
characters in a string:
Uri.HexEscape()
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
string
>

Trim all characters after the first " . " help need...

I need a really basic line of code which i can not find. I need to do is remove ALL characters after and inc the characters "." found in a variable. i have a variable which holds device with DNS name such as E096064-FWSM2.netdevice.companyname.com i want the variable to just hold the name E096064-FWSM2 the extension after the first "." can very greatly so i can not specify all possible options as i just do not know what they are going to be.

really hope someone can help me

paul

code below did the job

DNSnode = Left(fullDNSname, InStr(fullDNSname, ".")-1)

trim a URL link through datagrid

Hi,

Is there anyway I can trim this URL?

The Output is something like this:http://www.test.com/default.aspx?siteid=1&pagetitle=this_is_a_test and I want to get rid of everything past "?" so it just showshttp://www.test.com/default.aspx

This is the code i am using to get the URL through a datagrid in C#: 'Navigate='<%# Databinder.Eval(Container.DataItem, "LinkPath") %>' How can I trim this URL in the backend?

Thanks for anyone that can help me out.

Hi

Hope this helps

//Create a method calledstring GetTrimmedURL(string CompleteURL){ string TrimmedURL = String.Empty; string str = CompleteURL;int intIndexOfchar = str.IndexOf("?"); TrimmedURL = str.substring(intIndexOfchar, (str.Length() - intIndexOfchar));return TrimmedURL;}

Call this method at the place where you are doing the data binding. Say something like

'Navigate='<%# GetTrimmedURL(Databinder.Eval(Container.DataItem, "LinkPath")) %>'

Please note that this trims from the first instance of question mark though.

Hope this helps

Note: Pls watch out for small syntactical errors. Did this on a notepad.

VJ


Hi

You can do the following to strip the querystring off the URL:

Uri linkPath =new Uri(YOUROBJECTHERE.LinkPath);string newLinkPath = linkPath.Scheme + "://" + linkPath.Host + linkPath.AbsolutePath;

You could either do this is in the class you are databinding to, or perhaps in an OnItemDataBound event handler on your DataGrid, depending on your preference.

Hope this helps.

Seb

Trim Each textbox control - Repost

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Can you help?

Many Thanks!

AlexHi,

here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu

However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!

So far I've got this code:

-----------

Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox

For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl

-----------

I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.

Sorry but can you or somebody help in this casting so I can update or
get the text property?

Thanks

Alex

"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cast
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.c om...
> > HI
> > I'm trying to iterate through all the textboxes on a webpage and trim
> > them for spaces.
> > i.e. If a user enters " hello world " we correct it to "hello
> > world"
> > So far I've come up with this:
> > -----------------------
> --
> > 'Trim all textboxes
> > Dim ThisControl As System.Web.UI.Control
> > For Each ThisControl In Me.Controls
> > If ThisControl.GetType().ToString() =
> > "system.Web.UI.WebControls.TextBox" Then
> > ThisControl.text = Trim(ThisControl.text)
> > 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> > stuck! Please help...
> > End If
> > Next ThisControl
> > -----------------------
> --
> > The problem I have is not really with the trim function. It's the fact
> > that I cannot update the control text value. It won't allow the .text
> > property at all in this example because "thiscontrol" is not actually
> > aware that the control assigned to it is actually a textbox. Is there a
> > way to tell it it's a textbox so I can access this property, or is there
> > another way around this?
> > Can you help?
> > Many Thanks!
> > Alex

Trim Each textbox control

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
Can you help?
Many Thanks!
Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.
"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Any answers folks?
Cheers
Alex
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim Each textbox control

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

Can you help?

Many Thanks!

Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.

"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Any answers folks?

Cheers

Alex

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim function in VB.NET

Hey,

In my code the value of strWebService is initially "2 " (that is the number two followed by a space). I then use trim to eliminate the space:


strWebService = readHtmlPage(strTMQuery)
strWebService = Trim(strWebService)

I then run strWebService through a SELECT statement and it always defaults to ELSE:

Select Case strWebService
Case "0"
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case "1"
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case "2"
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select

What am I doing wrong?

MikeHello -

Perhaps you might want to do a conversion to an integer for the case statement?

good luck

take care
tony
I added the following line before my select statement:

Dim intWebService As Integer = CInt(strWebService)

I then removed the double quotes from my case expressions and ran the code but still got the ELSE statement. VB doesn't require BREAK does it?
did you trying doing a response.Write(intWebService) right before the case statement so you can verify the value?


response.write("service =" & strWebService & ".")

Take note of the spaces and period. Should be
service =2.
My code now reads like this (I added the = signs to the label just to make sure the TRIM did its job...)


strWebService = readHtmlPage(strTMQuery)
strWebService = RTrim(strWebService)
Dim intWebService As Integer = CInt(strWebService)

lblTest.Text = "=" & intWebService.ToString & "="
lblTest.Visible = True

Select Case strWebService
Case 0
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case 1
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case 2
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select

I still get the ELSE... Plus, my label does infact read 2... I don't get what I could be doing wrong...
Your select Statement is still referring to strWebService... Change it to intWebService...
Ha ha, good call. It works. Thanks guys. Strings in SELECT CASE statements SUCK!

trim function

does anyone knows what does Trim(!Delete & "") means? what is this Delete ?
thanks
Regards
GohIs it a boolean or some string variable declared elsewhere in your code?
Apparently this isn't an ASP.NET question, the 'original' post is here:

http://www.vbforums.com/showthread.php?p=2067378#post2067378

Trim fields in Text File

Hi

I have a text file with 116 fields separated by commas. How would I open the text file and trim all white spaces from each field and then close file?

Thanks

You can Use String.Split function to get array of all string with whitespace than trim that string and Use String.Join function to get comma seperated string

than store it in file


Even simpler would be to run a regex replace on your textfile after readingit.

Regex.Replace(strInput, "\s+", " ")

Trim Each textbox control - Repost

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?
Many Thanks!
AlexHi,
here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97
If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu
However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!
So far I've got this code:
Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl
I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.
Sorry but can you or somebody help in this casting so I can update or
get the text property?
Thanks
Alex
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP1
1.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cas
t
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.com...
> --
> --

trim left 5 character.

Hi guys

I am using vb.net

I have this "12.95-ups ground" string and I need to get the string after the dash

could you send me your suggestions please.

thanks

Cemal

Hi, try this:

Dim myStrAs String ="12.95-ups ground"Dim myTrimAs String = Mid(myStr, InStr(myStr,"-") + 1)

try something like below

index=yourStringVariable.IndexOf(".");
then
YourString.Substring( check what parameter this function requires)


string _strTest = "12.95-ups ground";
Response.Write ( _strTest.Substring ( 6 ) ) ;

Thanks

-Mark post(s) as "Answer" that helped you


dim str as string

str="12.95-ups ground"

dim newVal as string

newVal=str.substring(str.indexof("-")+1)

response.write(newVal)

trim large text

Hi! I have a function that trim large text, but the problem is that it cuts off the last word, so it's not making sense. Is there a function that trim large text in a nice way, making sure the last word is preserved. Thanks for any tip!

Can you just use Trim(myString) ?


You could also use Regular expressions :

using System.Text.RegularExpressions;

private string RemoveSpaces(string str)
{
string result = "";
Regex regulEx = new Regex(@."[\s]+");
result = regulEx.Replace(str," ");
return result;
}

Original code :Laxshmi

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--



I probably didn't explain what I am doing. If I have a large text to pull from the database and I 'd like just a small portion to be displayed in gridview cell, I am uisng:

Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) but this cuts off any last words.


Thank you for the reply! I am looking to shorten text (pulled out of the database)for display in gridview.

Cheers!


:)

Here you go. Even though this is asp code, you will get the idea

http://www.codeproject.com/asp/textpreview.asp

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


James,

if I understand you right then you're saying that you want the last word within the 100 character max limit to be preserved and to not be chopped in two, right? Here's a bit of code that might accomplish it for you if that is what you're looking for. It just involves string manipulations is all.

string myStr ="This string should be cut off at the 25th character, and preserve the final word.";string myStr25 = myStr.Substring(0, 25);int lastIdx = myStr25.LastIndexOf(" ");string finalStr = myStr25.Substring(0, lastIdx);

Let me know if you need help from there, but you should be able to adapt it to your need.


If you don't want to cut off words, just trim to the last index of a space.

string text = Eval("Bulletin").ToString();

if (text.Length > 100)

{

text = text.Substring(0, 100);

text = text.Substring(0, text.LastIndexOf(' ') + 1);

}


or how about trying this :

<ItemTemplate>
<%# Eval("Bulletin").ToString().Substring(0, 20) + "..." %>
</ItemTemplate>

Just make sure that all the strings are above 20 characters.

Edit : This code would probably cut off the last words. I do not have my visual studio with me, but what you can do is use this code with the suggestion posted by other members to get your solution.

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


I did this but it gave me 95 instead of my text:

<%# Eval("Bulletin").ToString().Substring(0,100).LastIndexOf(" ")%>

I am doing it in the aspx, makes it harder for me.


This is my datalist:

<asp:DataListID="dlBulletins"runat="server">

<ItemTemplate>

<strong><%# Eval("DisplayName")%></strong>

<br/>

<%#formatDate((DateTime)Eval("Bulletin_Date"))%><br/>

<%# Eval("Bulletin").ToString().Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) %>

</ItemTemplate>

How can I use the string text in datalist template?

Cheers!

<separatorTemplate><hrnoshade="noshade"size="1"/>

</separatorTemplate>

</asp:DataList></p>


I am using this but it's only returning the first letter!!

<%# Eval("Bulletin").ToString().Substring(0,100).Substring(0,Eval("Bulletin").ToString().LastIndexOf(' ')) %>


It sounds like it's impossible to do this in the datalist!


Thanks friend!! I don't know what i was thinking, I made a function in the code behind called trimtext, then used it in the aspx. Work great now!

Cheers!

Trim String

Hi

I want to trim the end of a string placed on my page.

I want to make it so that even if the text is 100 char long it will only display the first 15 characters.

Is this correct, i cant seem to make it work.

Regards
Ant

<%#Container.DataItem("OutboundCarrierName").ToString.Trim("15") %>

use Substring function in place of this:

<%#Container.DataItem("OutboundCarrierName").ToString().Substring(0,15) %>

thanks


Perfect, that works.

trim querystring

Is there a way to request the whole querystring after the "?"

I want to pull every name value pair out of the querystring in one string.

Thanks!

mike123You may try "Request.QueryString".
No luck

Anything else ?

Thanks!
mike123
I think Request.ServerVariables("QUERY_STRING") will return what you are after?

Simon

Trim TextBox spaces

I am facing difficulity of having to Trim Spaces in Textbox.I am given a task of needing to trim spaces in the textbox and not to allow space at the front and at the back of the textbox as when u enter a space in front of the textbox it will be a totally different data from the one which has no space. So can anyone help me about the trim in Asp.net 2.0 c# languague.

<trclass="i4">

<tdclass="i5">

<span><span><spanclass="i6">C</span>USTCODE</span><spanclass="i6">

</span>

</span>

</td>

<tdclass="i7">

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="CUSTCODETextBox"

ErrorMessage="*"Font-Bold="False"></asp:RequiredFieldValidator></td>

<tdcolspan="2"class="i8">

<asp:TextBoxID="CUSTCODETextBox"runat="server"Text='<%# Bind("CUSTCODE") %>'MaxLength="20"></asp:TextBox></td>

<tdrowspan="10"class="i9"></td>

When you are saving the data in your code behind, you can trim the text using this code:

string customerCode = CUSTOMCODETextBox.Text.Trim();

That will get you the value entered by the user, without any leading or trailing spaces.