This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
The array consists of 100 items. I need to initialize elements of the array which sequential numbers starting from -2.
You mean SomeArray[-2]? It's not possible, as a value inside [ ] brackets are indexes, and it they can't be negative numbers (but the index starts from 0)... It's like having minus 2nd apple in your basket.
But if you mean values, you can do it easily by a loop
for (i=0; i<=100; i++) {
SomeArray[i] = i-2;
}
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code:
'Files' is a List<string> and _indx is an int.
label22.Text = files[_indx];
For example in 'files' in index[0] I have this string:
D:\New folder (45)\converted.avi_Automatic\Lightning 0 Length 2 [91 - 93]\000091.bmp
But instead in label22.Text I want it to show me only '000091.bmp' without the rest of the directory path.
How can I do it ?
Use Path.GetFileName:
label22.Text = Path.GetFileName(files[_indx]);
I believe you are looking for Path.GetFileName():
label22.Text = Path.GetFileName(files[_indx]);
Path.GetFileName(fileName) returns the file name without the directory.
taken from http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.100).aspx
The simplest way is
Path.GetFileName(files[_indx]);
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have 2 instances of IEnumerable<string> and need to iterate over both of them. Is it possible to iterate within single foreach?
Have a look at Enumerable.Concat(). I think it will do what you want:
foreach (string str in Enumerable.Concat(collection1, collection2))
{
}
Or
foreach (string str in collection1.Concat(collection2))
{
}
Union will not work unless you want to iterate over the set union of the two IEnumerable. The set union is defined as the unification of both, without duplicates. So if you rely on iterating over duplicates, it will not work, you'll have to use Concat for that.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I came across this C# literal and was wondering what does it mean?
Especially, in the following case:
string.Format("{0:x}", byteArray[i]);
Thanks
It means format the first argument (index 0) as hexadecimal: http://msdn.microsoft.com/en-us/library/s8s7t687(v=vs.80).aspx
It means the first argument will be output as hexadecimal (in lowercase !!).
To output uppercase you could use "{0:X}".
Look msdn for more info about string formatting : MSDN Custom string format
This represents the hexadecimal format.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
How do I check if the string reader has passed a certain line number, or has passed a line number which contains some text? I put this in the line processing code of a string reader:
if (currentline.Contains("123"))
currentbank = "123";
else if (currentline.Contains("456"))
currentbank = "456";
else if (currentline.Contains("789"))
currentbank = "789";
I want to change the contents of a string based on what range of line numbers it is in, with my code it always gives 123. Like for example if it's from lines 10-20 (or from 123 to 456) then the string should have 123, 20-30 (or 456 to 789) it should have 456 and 30-40 have 789. How can I do this using a StringReader?
Fixed it myself, problem being I used upper case (e.g. TEST) instead of lower case.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Suppose the string is:
string item = "t-ewrwerwerwerwer\r-rr\wrjkwlr";
I want to Replace all - except when it is preceded by r.
So resut will be
string cleanItem = "tewrwerwerwerwer\r-rr\wrjkwlr"'
What regular expression can be used?
I think this regular expression is a little more efficient:
-(?<!r-)
Or if your language doesn’t support negative look-behind assertions, use this expression:
(^|[^r])-
and replace it by \1 (first matching group).
A replacement on (?<!r)- by an empty string should do the trick I think.
(?<!r)-
As long as your regex flavor supports zero-width look-behind, that is.