I have a strange problem.
I have a local string() var I populate this way:
clmns() As String = {"InvoiceNo" , "InvoiceDat e"}
When I call:
Array.IndexOf(c lmns,"InvoiceDa te") I get 0 (zero) as expected.
If I fetch the values from the web.config this way:
clmns() As String =
ConfigurationSe ttings.AppSetti ngs("clmns").Sp lit(",")
(in my web.config I have: <add key="clmns" value="InvoiceN o,
InvoiceDate" />)
I get -1 when I call:
Array.IndexOf(c lmns,"InvoiceDa te")
Looking at the clmns var (regardless of how it is populated) in my
debug window reveals identical structure and type.
Do the split method produce a different type than the = {"", ""} way?
Morten 3 1610
Morten71 wrote:
I have a strange problem.
I have a local string() var I populate this way:
clmns() As String = {"InvoiceNo" , "InvoiceDat e"}
When I call:
Array.IndexOf(c lmns,"InvoiceDa te") I get 0 (zero) as expected.
If I fetch the values from the web.config this way:
clmns() As String =
ConfigurationSe ttings.AppSetti ngs("clmns").Sp lit(",")
(in my web.config I have: <add key="clmns" value="InvoiceN o,
InvoiceDate" />)
I get -1 when I call:
Array.IndexOf(c lmns,"InvoiceDa te")
Looking at the clmns var (regardless of how it is populated) in my
debug window reveals identical structure and type.
Do the split method produce a different type than the = {"", ""} way?
Morten
The problem is that you are comparing the strings by reference, not by
value.
Literal strings are stored as constants in the code. The compiler looks
for identical strings in the code where it can reuse the contants. When
you create the array from literal strings and compare to another literal
string, the matching strings aren't just equal, they are actually the
same string.
When you create the array by splitting a string, it produces new strings
at runtime, so the compiler can't reuse the constants in the code. The
matching strings have the same value, but they are two separate strings.
As you are comparing the strings by reference and not by value, they
won't match.
To match the strings by value, you should use the generic form of the
Array.IndexOf method.
--
Göran Andersson
_____ http://www.guffa.com
Morten71 wrote:
<snip>
I have a local string() var I populate this way:
clmns() As String = {"InvoiceNo" , "InvoiceDat e"}
When I call:
Array.IndexOf(c lmns,"InvoiceDa te") I get 0 (zero) as expected.
I guess you meant "1 as expected"...
If I fetch the values from the web.config this way:
clmns() As String =
ConfigurationSe ttings.AppSetti ngs("clmns").Sp lit(",")
(in my web.config I have: <add key="clmns" value="InvoiceN o,
InvoiceDate" />)
I get -1 when I call:
Array.IndexOf(c lmns,"InvoiceDa te")
Looking at the clmns var (regardless of how it is populated) in my
debug window reveals identical structure and type.
Are you sure there isn't an extra space before "InvoiceDat e"?
HTH.
Regards,
Branco.
Morten,
In my idea is there written that the method search for objects in an array
of objects.
Nowhere is written that it has any relation with the string.indexof which
search for characterstring s inside a characterstring . http://msdn2.microsoft.com/en-us/lib...y.indexof.aspx
Cor
<Morten71schree f in bericht
news:fb******** *************** *********@4ax.c om...
>
I have a strange problem.
I have a local string() var I populate this way:
clmns() As String = {"InvoiceNo" , "InvoiceDat e"}
When I call:
Array.IndexOf(c lmns,"InvoiceDa te") I get 0 (zero) as expected.
If I fetch the values from the web.config this way:
clmns() As String =
ConfigurationSe ttings.AppSetti ngs("clmns").Sp lit(",")
(in my web.config I have: <add key="clmns" value="InvoiceN o,
InvoiceDate" />)
I get -1 when I call:
Array.IndexOf(c lmns,"InvoiceDa te")
Looking at the clmns var (regardless of how it is populated) in my
debug window reveals identical structure and type.
Do the split method produce a different type than the = {"", ""} way?
Morten
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin C |
last post by:
Quick Question:
StringBuilder is obviously more efficient dealing with string concatenations
than the old '+=' method... however, in dealing with relatively large string
concatenations (ie, 20-30k), what are the performance differences (if any
with something as trivial as this) between initializing a new instance of
StringBuilder with a specified capacity vs. initializing a new instance
without... (the final length is not fixed)
ie,
|
by: Davy |
last post by:
Hi all,
I found
char x={"my"};
can be compiled.
But
char x;
x={"my"};
can not be compiled.
|
by: Dan V. |
last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to
pass in a table or query as a parameter and have both columns transform into
a 2D ArrayList. When I sort the one 'column' in the ArrayList, the other is
automatically sorted and so I can use IndexOf without fear. This is because
I will be going through 20,000 some odd records and don't want to use a
Lookup type of table/query; I figure an ArrayList.IndexOf method...
|
by: Asha |
last post by:
greetings, i have some questions below, what are the differences between
private string _strVal = string.Empty; and _strVal = null;
does the string.Empty; allocate memory for it? how about _strVal = ""
thanks for enlightening me on this.
|
by: Samuel R. Neff |
last post by:
Are there any differences between using Array.Length and
Array.GetUpperBound(0) on a one-dimensional array?
We have a team of developers and most people use Array.Length but one
developer uses GetUpperBound(0). I'd like the code to all be
consistent but would like to know if there is any other reason I can
provide to justify using only Array.Length instead of
GetUpperBound(0).
I read that Array.Length has special meaning to the...
| |
by: Kyro |
last post by:
New to C# (migrating from Delphi) and I'm not sure how to get a
delimited string into an array of string.
input: string looks like - 01-85-78-15-Q11
output: an array with elements - 01,85,78,15 etc...
Is there some sort of easy one liner that does this? Hard to search
the help files for anything that would assist me in doing this.
Thanks in advance.
|
by: Andrea |
last post by:
Hi,
suppose that I have a string that is an hexadecimal number, in order
to print this string I have to do:
void print_hex(unsigned char *bs, unsigned int n){
int i;
for (i=0;i<n;i++){
printf("%02x",bs);
}
}
|
by: polas |
last post by:
Good morning,
I have a quick question to clear up some confusion in my mind. I
understand that using a string literal in a declaration such as char
*p = "string literal" declares a pointer to memory holding the string
and the string might very well be held in read only memory.
However, I am sure that I read somewhere that the declaration char a
= "string literal", even though a is an array (and I understand the
differences between...
|
by: George2 |
last post by:
Hello everyone,
Suppose we defined a string buffer (array), like this,
char array = "hello world";
char buf
Sometimes, I noticed that we either use,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |