Hi,
Using C# I'm trying to use the substring method of a string variable but it
just generates an "error: 'variable.Substring' does not exist " exception -
how do I fix this ?
code example:
string creationDateStr = string.Empty;
string anotherStr = "";
creationDateStr = "some string or other";
anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks, 15 6053
you have to make sure that there is something in your string variable.
if len(creationdatestr) > 2 then
creationdatestr.substring(0,2)
else
messagebox.show("string not long enough")
end if
this is vb syntax... I'm sure you can change it to c# ;-)
"Duncan Allen" wrote: Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
Thanks, but the string variables are populated and still no joy.
"interwanderer" wrote: you have to make sure that there is something in your string variable.
if len(creationdatestr) > 2 then creationdatestr.substring(0,2) else messagebox.show("string not long enough") end if
this is vb syntax... I'm sure you can change it to c# ;-)
"Duncan Allen" wrote:
Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
use one of the following functions. left, right or mid.
"Duncan Allen" wrote: Thanks, but the string variables are populated and still no joy.
"interwanderer" wrote:
you have to make sure that there is something in your string variable.
if len(creationdatestr) > 2 then creationdatestr.substring(0,2) else messagebox.show("string not long enough") end if
this is vb syntax... I'm sure you can change it to c# ;-)
"Duncan Allen" wrote:
Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
I have had no problems with your code (although I am still using VS2005 Beta
2). It returs "so" all the time.
Fitim Skenderi
"interwanderer" <in***********@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com... use one of the following functions. left, right or mid.
"Duncan Allen" wrote:
Thanks, but the string variables are populated and still no joy.
"interwanderer" wrote:
> > you have to make sure that there is something in your string variable. > > if len(creationdatestr) > 2 then > creationdatestr.substring(0,2) > else > messagebox.show("string not long enough") > end if > > this is vb syntax... I'm sure you can change it to c# ;-) > > "Duncan Allen" wrote: > > > Hi, > > > > Using C# I'm trying to use the substring method of a string variable > > but it > > just generates an "error: 'variable.Substring' does not exist " > > exception - > > how do I fix this ? > > > > code example: > > > > string creationDateStr = string.Empty; > > string anotherStr = ""; > > creationDateStr = "some string or other"; > > anotherStr = creationDateStr.Substring(0,2); > > > > This compiles but errors at run time. > > > > Thanks, > > > > > > > > > > > > > >
C# doesn't seem to have Left, right or mid ......
"interwanderer" wrote: use one of the following functions. left, right or mid.
"Duncan Allen" wrote:
Thanks, but the string variables are populated and still no joy.
"interwanderer" wrote:
you have to make sure that there is something in your string variable.
if len(creationdatestr) > 2 then creationdatestr.substring(0,2) else messagebox.show("string not long enough") end if
this is vb syntax... I'm sure you can change it to c# ;-)
"Duncan Allen" wrote:
> Hi, > > Using C# I'm trying to use the substring method of a string variable but it > just generates an "error: 'variable.Substring' does not exist " exception - > how do I fix this ? > > code example: > > string creationDateStr = string.Empty; > string anotherStr = ""; > creationDateStr = "some string or other"; > anotherStr = creationDateStr.Substring(0,2); > > This compiles but errors at run time. > > Thanks, > > > > > > >
Interwander, if len(creationdatestr) > 2 then creationdatestr.substring(0,2) else messagebox.show("string not long enough") end if
this is vb syntax... I'm sure you can change it to c# ;-)
You can but is is a little bit without sense
Cor
Duncan,
In my opinion should your code run, is it not something around that.
Cor
"Duncan Allen" <Du*********@discussions.microsoft.com> schreef in bericht
news:6F**********************************@microsof t.com... Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
maybe not standard but you can import a namespace that does
in C# it is USE i think?
use Microsoft.VisualBasic
Strings.Left(str, Length)
.....
click yes if this post was helpfull :-D
"Duncan Allen" wrote: C# doesn't seem to have Left, right or mid ......
"interwanderer" wrote:
use one of the following functions. left, right or mid.
"Duncan Allen" wrote:
Thanks, but the string variables are populated and still no joy.
"interwanderer" wrote:
> > you have to make sure that there is something in your string variable. > > if len(creationdatestr) > 2 then > creationdatestr.substring(0,2) > else > messagebox.show("string not long enough") > end if > > this is vb syntax... I'm sure you can change it to c# ;-) > > "Duncan Allen" wrote: > > > Hi, > > > > Using C# I'm trying to use the substring method of a string variable but it > > just generates an "error: 'variable.Substring' does not exist " exception - > > how do I fix this ? > > > > code example: > > > > string creationDateStr = string.Empty; > > string anotherStr = ""; > > creationDateStr = "some string or other"; > > anotherStr = creationDateStr.Substring(0,2); > > > > This compiles but errors at run time. > > > > Thanks, > > > > > > > > > > > > > >
Duncan,
The Left, Right, and Mid are just a part of the Visual Basic namespace the
same as other namespace that you use in C#.
However, if it is only for this it has very few sense. (It has inbuild
checking if by instand the second parameter of a substring is not going
outside the string length and make that second parameter than accoording the
length)
However that is not in this case.
I hope that this gives an idea.
Cor
OK, analysed the problem a bit more and basically no string object is being
treated as an object - so maybe I need to re-register something .... ?
Stuff like ...
myArray[0].ToUpper();
or even myString.ToString()
doesn't work either .....
"Cor Ligthert [MVP]" wrote: Duncan,
In my opinion should your code run, is it not something around that.
Cor
"Duncan Allen" <Du*********@discussions.microsoft.com> schreef in bericht news:6F**********************************@microsof t.com... Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
Duncan Allen <Du*********@discussions.microsoft.com> wrote: Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon,
Duncan gave his own answer on the last line to me.
Cor
Cor Ligthert [MVP] wrote: Duncan gave his own answer on the last line to me.
But not in a way which really shows the root of the problem. There's
clearly something wrong in how his variables are being set up in the
first place - and a short but complete program would demonstrate that.
Jon
On Wed, 23 Nov 2005 06:59:09 -0800, Duncan Allen wrote: Hi,
Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ?
code example:
string creationDateStr = string.Empty; string anotherStr = ""; creationDateStr = "some string or other"; anotherStr = creationDateStr.Substring(0,2);
This compiles but errors at run time.
Thanks,
Check in your references that you haven't removed 'System', as this is
responsible for providing the base object types such as String.
Also, check that 'Imported Namespaces' also has a reference to System.
Cheers,
Jason
JasonS <ga****@sobell.net> wrote:
<snip> Check in your references that you haven't removed 'System', as this is responsible for providing the base object types such as String. Also, check that 'Imported Namespaces' also has a reference to System.
Slight correction - the System assembly doesn't contain System.String -
mscorlib does.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: juglesh |
last post by:
hello, I've put in my time searching, so I'll ask now<G>
I need to look at the url, if a variable is present in the query string.
so, if my address bar looks like:...
|
by: LongBow |
last post by:
Hello all,
I am having a little problems getting String's StartsWith and
EndsWith methods. If I have a string defined as
sNormalPt which equals "0x11D0" then use the following command
...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: rsine |
last post by:
I have developed a program that sends a command through the serial port
to our business system and then reads from the buffer looking for a
number. Everything worked great on my WinXP system, but...
|
by: Chris Dunaway |
last post by:
I have a table in the database with a phone number field. The phone number
is stored without any punctuation (e. g. 9995551234). I wish to take that
string and format it for display (e. g. (999)...
|
by: Charles Law |
last post by:
I have a string similar to the following:
" MyString 40 "Hello world" all "
It contains white space that may be spaces or tabs, or a combination, and I
want to produce an array...
|
by: archana |
last post by:
Hi all,
I am facing some wierd problem in quick watch at a time of debugging
my application.
I have one variable of type string, say suppose i have code as below:
string FileName;...
|
by: Mike Collins |
last post by:
I know I am going to feel really dumb when someone tells me the answer, but
at the moment, I am stumped.
What is wrong here and how can I fix it?
string id = dropDownList.ID
?id...
|
by: rnakawat |
last post by:
I seem to have a problem using the preceding:: on substrings of the
value. I'll try to explain with an example:
Let's say I had a XML that look like:
<Root>
<Row>
<Cell Name="Street"...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |