string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration
string manipulation--a little frustration string manipulation--a little frustration
string manipulation--a little frustration
Go Back  Xtreme Visual Basic Talk > > > string manipulation--a little frustration


Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2010, 12:49 PM
celtic celtic is offline
Centurion
 
Join Date: Mar 2009
Posts: 132
Default string manipulation--a little frustration


Hi all.

I want to just get the leftmost characters from a string.
Something that should be very simple...and yet!

Here is an example:
Code:
Dim strA As String = Now.ToString
strA = Strings.Left(strA, Len(strA - 1))
Why does this return an error: "Conversion from string to double is not valid."

--Mike
Reply With Quote
  #2  
Old 06-21-2010, 01:24 PM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

looks like you were subtractiong 1 from a string

Code:
Dim strA As String = Now.ToString
strA = Strings.Left(strA, Len(strA)-1)
Reply With Quote
  #3  
Old 06-21-2010, 01:26 PM
AtmaWeapon's Avatar
AtmaWeaponstring manipulation--a little frustration AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Because you're not paying attention. Len(strA - 1) tries to subtract 1 from strA. Since it's a string, it doesn't make any sense to attempt this operation.

Personally, I'd rather use String.Substring() rather than the Microsoft.VisualBasic crutch class Strings. It's much more convenient to look for methods on object instances than to look for utility classes. For example:
Code:
strA = strA.Substring(0, strA.Length - 1)
That's a direct translation of what you were trying to do, and isn't much more difficult. (I do wish they had put a .Left() and .Right() member on the String class, but it's not difficult to find equivalent uses for Substring.)
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 06-22-2010, 12:21 PM
celtic celtic is offline
Centurion
 
Join Date: Mar 2009
Posts: 132
Default

Thank you Centurion, AtmaWeapon.

Yes...so many details in .net, my brain gets tired...I knew it was simple but just couldn't see it

--Mike
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration string manipulation--a little frustration
string manipulation--a little frustration
string manipulation--a little frustration
 
string manipulation--a little frustration
string manipulation--a little frustration
 
-->