|
I guess that's what I get, I forgot to take my umm... what's it called... that stuff that makes you remember better? darn it.
Thanks for the correction.
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
|
Pete O'Hanlon wrote: BTW - the conditional is called the ternary operator.
Which BTW is quite a silly name, as it only means "three operand operator", and doesn't say anything at all what the operator does with the operands.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hy everyone!
i was wondering if there is a default string function to cut a string if it is to long to e.g. insert it into a textfield.
what i want to do:
i created a table which allows strings up to a maximum length. if it is too long i have to cut the rest.
lets say there is a string
"1,2,3,4,5,6,7,8,9,10" but the maximum length, which could be insert is 16 characters so the maximum string would be e.g. "1,2,3,4,5,6,7,8," but is there a chance to cut it to this length without having to parse it or without having to insert 16 characters one by one in a loop?
thanks.
stephan.
|
|
|
|
|
string s = "1,2,3,4,5,6,7,8,9,10";
string cut = s.Substring(0, 16);
so:
s = "1,2,3,4,5,6,7,8,9,10";
cut = "1,2,3,4,5,6,7,8,";
|
|
|
|
|
It would be best to check the length before trying to substring that... I don't think anyone likes argument out of range exceptions....
|
|
|
|
|
thanks for the hints. i guess the best solution will be
if (mystring.length > maximumlength)
{
mystring = mystring.Substring(0, maximumlength);
}
so if the string is already smaller than the maximum length, then it is easy to insert it, but if it is longer, then just the first characters (up to maximumlength) should be insert.
thanks again for the hints. i didn't know it was this easy
stephan.
|
|
|
|
|
good morning from montreal,
i am working with a TURBO C 2.01 compiler -
with which i am still very satified - but i can't find anywhere a good
article how to incorperate ASSEMBLY language with this compiler. that's
really all for now. of course if someone could show me a SIMPLE code
fragment, from way back when, that's really all i,d like. So thanks
beforhand. allan.
|
|
|
|
|
you asked in the wrong forum.
this forum is about C#, a rather recent language, quite different from good old C.
I suggest you ask again in the C/C++ forum (unmanaged, no CLI), but even then don't
hold your breath...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
It's been a really long time, but I think Borland used the following:
single line:
asm mov ah, 9
or a block:
asm
{
mov ax, 1234h
mov bx, ax
}
Hope that works. I think you can also link in your ASM files but that part of my brain has been overwritten.
|
|
|
|
|
I get an InvalidCastException in the bold part of the code (the "" and /object are not part of the code)
public void AthugaStafset()
{
SortedList SL = new SortedList();
SortedList SL2 = new SortedList();
SL.Add(0, "V1");
SL.Add(1, "V2");
SL.Add(2, "V3");
SL.Add(3, "V4");
SL.Add(4, "V5");
SL2.Add(0, richTextBox1.Text);
SL2.Add(1, richTextBox1.Text);
SL2.Add(2, richTextBox1.Text);
SL2.Add(3, richTextBox1.Text);
SL2.Add(4, richTextBox1.Text);
bool equal = Compare(SL, SL2);
if (equal)
{
richTextBox2.Text = "Right";
}
else
{
richTextBox2.Text = "They differ";
}
}
static bool Compare(SortedList SL, SortedList SL2)
{
if (SL.Count != SL2.Count)
{
return false;
}
foreach (KeyValuePair<object, string=""> item in SL)
{
if (!SL.Contains(item.Key))
{
// Return the moment we find a difference
return false;
}
}
// Must be the same
return true;
}
|
|
|
|
|
Change KeyValuePair<> to DictionaryEntry.
Remember to use the "code" and "pre" tags when posting code.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
That worked, but now everything is equal or correct, even if I type in a wrong string.
|
|
|
|
|
I was waiting for you to get to that. You are comparing the Keys to both lists, not the Values. And the Keys in both lists are identical. Your compare function needs work.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
|
Firstly, take more than a minute and consider the problem. Give it like ten.
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Which I have.
This is the Compare code. I suspect it has something to do with the bold text. BUt I can´t put my finger on it.
static bool Compare(SortedList SL, SortedList SL2)
{
if (SL.Count != SL2.Count)
{
return false;
}
foreach (DictionaryEntry item in SL)
{
if (!SL.ContainsKey(item.Key))
{
return false;
}
}
return true;
}
|
|
|
|
|
Is this homework?
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Not really, I am taking a course in C# but this is more of a side project I´d like to finish.
|
|
|
|
|
Here's a hint - you're reading from the SL sorted list, and then checking to see if the same sorted list contains the key. Change it to point to the right list:
foreach (DictionaryEntry item in SL)
{
if (!SL2.ContainsKey(item.Key))
{
|
|
|
|
|
|
Hmmmm....
This seems like an Equality problem...
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Equality... Equality... Equality...
A is equal to B if A = B and B = A
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
But it's a list. That'll bugger things up.
A.items == B.items & B.items = A.items
Duplicates could mess you up.
pseudocode:
foreach thingy in A{
make sure thingy is in B.Thingies
}
foreach thingy in B {
make sure thingy is in A.Thingies
}
Help any?
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
not really, if you could incorporate it into the Compare code I posted it may shed some light.
|
|
|
|
|