If I have an array named $myArray how can I get a reference to it from a string of the same name myArray. I tried:
eval('myArray');
But that gave me an error.
This is the code I've seen so far to delete last 3 lines in a text file, but it's required to determine string[] lines = File.ReadAllLines(); which is nt necessary for me to do so.
string[] lines = File.ReadAllLines(@"C:\\Users.txt");
StringBuilder sb = new StringBuilder();
int count = lines.Length - 3; // except last 3 lines
for (int s = 0; s < count; s++)
{
sb.AppendLine(lines[s]);
}
The code works well, but I don't wanna re-read the file as I've mentioned the streamreader above :
using (StreamReader r = new StreamReader(@"C:\\Users.txt"))
Im new to C#, as far as I know, after using streamreader, and if I wanna modify the lines, I have to use this :
while ((line = r.ReadLine()) != null)
{
#sample codes inside the bracket
line = line.Replace("|", "");
line = line.Replace("MY30", "");
line = line.Replace("E", "");
}
So, is there any way to delete the last 3 lines in the file within the "while ((line = r.ReadLine()) != null)" ??
I have to delete lines, replace lines and a few more modications in one shot, so I can't keep opening/reading the same text file again and again to modify the lines. I hope the way I ask is understable for you guys .<
Plz help me, I know the question sounds simple but I've searched so many ways to solve it but failed =(
So far, my code is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication11
{
public class Read
{
static void Main(string[] args)
{
string tempFile = Path.GetTempFileName();
using (StreamReader r = new StreamReader(@"C:\\Users\SAP Report.txt"))
{
using (StreamWriter sw = new StreamWrite (@"C:\\Users\output2.txt"))
{
string line;
while ((line = r.ReadLine()) != null)
{
line = line.Replace("|", "");
line = line.Replace("MY30", "");
line = line.Replace("E", "");
line = System.Text.RegularExpressions.Regex.Replace(line, @"\s{2,}", " ");
sw.WriteLine(line);
}
}
}
}
}
}
Now my next task is to delete the last 3 lines in the file after these codes, and I need help on this one.
Thank you.
Hello there,
I have my WCF Service hosted in Windows Service. The client application is a website project to which I added the Service reference.
I was not using any error logging/tracing... but now I feel I should implement as it will help me not to make void guesses.
Please guide me for the best practice so that I can quickly handle errors and pin point the exact issue.
Thank you!
I am working on a webapplication
How can i create SQL for the following
Database Information
User information
Username - String
Password - String
Admin or Client - boolean
Last login – Date/Time
LogItem
typeLogItem – String (Page name?)
hitCount – int
View
PageURL
UserID
Transaction
User – String
DateTimeStamp
SKU – int
Purchase-boolean
TransactionID-int
Inventory information
Sku number - int
Item description - String
Price to customer - double
Count - in
I'm looking for a Python IDE that can help me easily locate and manage and use the libraries on my system (Ubuntu). Specifically Twisted.
Code completion is important including the symbols I import.
(I've so far had a look at PyDev as well as OpenKomodo, but while both offer code completion for default Python concepts, I wasn't able to get either to import Twisted into my project and was thus getting reference errors.)
Usual disclaimer: I don't like EMACS or vi, please, nothing regarding those.
hello.
Is it possible to have scoped macros using custom defined macros through boost wave?
I know it should a possible with C++0x however I am working with regular C++.
If it is possible, can you provide link or reference how to accomplish this?
Thanks
Hi,
what I want to do is to know where (not in terms of position (x, y), but a reference to the DOM element) an object was dropped.
I have a grid made up with divs where you can drop various items and I need to know which div on the grid was the item dropped on (getting its id would be fine). The callback function
function(event, ui) { //code here }
has just that ui object who doesn't apparently contain any information about this, but only about the draggable item or its helper.
hi,
i am using autocomplete with oracle Db,how to create unique keyword for the table.
KEYWORD VARCHAR2(100)
COUNT NUMBER(18)
how can i make as unique
can plz tell the query
Is it bad javascript practice to not assign a newly created object to a variable if you're never going to access it?
For example:
for(var i=0;i<links.length;i++){
new objectName(links[i]);
}
And again, I won't be accessing it, so there's no need for a variable to reference it.
My question is easily summarized as: "Why does the following not work?"
teststruct = struct('a',3,'b',5,'c',9)
fields = fieldnames(teststruct)
for i=1:numel(fns)
fns(i)
teststruct.(fns(i))
end
output:
ans = 'a'
??? Argument to dynamic structure reference must evaluate to a valid field name.
Especially since teststruct.('a') does work. And fns(i) prints out ans = 'a'.
I can't get my head around it.
Hi,
In C++, there is a fwrite() which writes a buffer to a file on disk:
http://www.cplusplus.com/reference/clibrary/cstdio/fwrite/
Can you please tell me if there is any buffer inside that fwrite implementation?
i.e. if I call fwrite() multiple times (say 10 times), does it actually invoke file i/o 10 different times?
Thank you.
When I run my C# program it throws an Stack Overflow exception in one of the methods on a DLL that I have a reference to it in my solution.
but no debugging info is available to me because it says it is an stack overflow exception and no info is available.
what are the next debugging steps that I should follow to understand what is going on and why ?
thanks
Edit: here is the code that stops at:
static public Collection SortCollection(Collection oCollection, string sPropertyName, string sKeyPropertyName)
{
return SortCollection(oCollection, sPropertyName, sKeyPropertyName);
}
I'm studying computer systems and I've made this very simple function which uses fork() to create a child process. fork() returns a pid_t that is 0 if it's a child process. But calling the getpid() function within this child process returns a different, nonzero pid. In the code I have below, is newPid only meaningful in the context of the program, and not to the operating system? Is it possibly only a relative value, measured against the pid of the parent?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
void unixError(char* msg)
{
printf("%s: %s\n", msg, strerror(errno));
exit(0);
}
pid_t Fork()
{
pid_t pid;
if ((pid = fork()) < 0)
unixError("Fork error");
return pid;
}
int main(int argc, const char * argv[])
{
pid_t thisPid, parentPid, newPid;
int count = 0;
thisPid = getpid();
parentPid = getppid();
printf("thisPid = %d, parent pid = %d\n", thisPid, parentPid);
if ((newPid = Fork()) == 0) {
count++;
printf("I am teh child. My pid is %d, my other pid is %d\n", getpid(), newPid);
exit(0);
}
printf("I am the parent. My pid is %d\n", thisPid);
return 0;
}
Output:
thisPid = 30050, parent pid = 30049
I am the parent. My pid is 30050
I am teh child. My pid is 30052, my other pid is 0
Lastly, why is the child's pid 2 higher than the parent's, and not 1? The difference between the main function's pid and its parent is 1, but when we create a child it increments the pid by 2. Why is that?
I need to grab the height of the window and the scrolling offset in jQuery, but I haven't had any luck finding this in the jQuery docs or Google. I'm 90% certain there's a way to access height and scrollTop for an element (presumably including the window), but I just can't find the specific reference.
Any help is appreciated! Thanks!
Hello!
I'm running this query:
SELECT DISTINCT CONCAT(ALFA_CLAVE, FECHA_NACI) FROM listado GROUP BY ALFA_CLAVE HAVING count(CONCAT(ALFA_CLAVE, FECHA_NACI)) > 1
Is there any way to optimize it? Queries are taking 2-3 hours on a table with 850,000 rows.
Adding an index to ALFA_CLAVE and FECHA_NACI would work?
Thanks in advanced
I've been trying to figure how whether the iPhone (either 3G or 3Gs) camera puts metadata into it's images. Anecdotally, it appears that it does (e.g., I've seen images posted on the web that included a bunch of metadata), but I can't find reference to it anywhere in the SDK documentation. So....does anyone have a definitive answer? Also, if there is metadata, how do I get at it?
This is strange:
DateList@AbsoluteTime[596523]
returns
{2078, 7, 2, 2, 42, 9.7849}
But
DateList@AbsoluteTime[596524]
returns
{1942, 5, 26, 20, 28, 39.5596}
The question: What's going on?
Note that AbsoluteTime with an integer argument is undocumented.
(I think I now know what it's doing but figured this is useful to have as a StackOverflow question for future reference; and I'm curious if there's some reason for that magic 596523 number.)
Some people are saying " stack variable store its value in HEAP ", and others saying " stack variable store store its value in DATA segment". I am totally confused with these conflict answers.
Where exactly static variable stores?. I am expecting an answer with standard reference ( text books, or good author tutorial).
I'm trying to find a good metaphor to explain memory allocation, initialization and freeing in c to a non technical audience. I've heard pass-by-reference/value talked about quite well with postal service usage, but not so much for allocation/deallocation.
So for I've thought about using the idea of renting a space might work, but I wonder if the SO crew can provide something better.
In the days of parallel printers one used to be able to send a command on LPT1 and receive back standard info such as life count etc.
Now, with USB devices, have we lost that capability? Or is there still a way to read the info?
Say I have a query like the one below. What would be the best way to put each value into an array if I don't know how many results there will be? Normally I would do this with a loop, but I have no idea how many results there are. Would I need run another query to count the results first?
<CFQUERY name="alllocations" DATASOURCE="#DS#">
SELECT locationID
FROM tblProjectLocations
WHERE projectID = '#ProjectName#'
</CFQUERY>
Firefox and Chrome are known to be slow on localhost when IP6 is enabled. In previous versions of Windows, the simplest fix is to comment out this line from the hosts file, as explained in the answer to this question.
::1 localhost
However, as noted in this question, in Windows 7 this line is already commented out:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
Is there an alternative way to disable the ::1 localhost reference in Windows 7?
Hello,
I have a the following table with rows:
================================================================
id | name | group1 | group2 | group3 | group4 |
================================================================
1 | Bob | 1 | 0 | 0 | 1|
================================================================
2 | Eric| 0 | 1 | 0 | 1|
================================================================
3 | Muris | 1 | 0 | 1 | 1|
================================================================
4 | Angela | 0 | 0 | 0 | 1|
================================================================
What would be the most efficient way to get the list with ActiveRecords ordered by groups and show their count like this:
group1 (2)
group2 (1)
group3 (1)
group4 (4)
All help is appreciated.
How to combine these two sql queries into one?
SELECT DISTINCT * FROM rss WHERE MATCH(content,title) AGAINST ('$filter')
SELECT COUNT(content) FROM rss WHERE MATCH(content,title) AGAINST ('$filters')
And if the result is 0 from the above query
-
SELECT DISTINCT * FROM rss WHERE content LIKE '%$filters%' OR title LIKE '%$filters%';
$filter .= $row['filter'];
$filters = $row['filter'];
$filters may be more than one keyword
In R, what is the most efficient way to count the length between 2 values. for example, i have vector x , which are all randomly choose from 1 to 100, how can i find out the length between the first"2" and first"40",
x=(1,2,3,4,5,6,7,40,1,2,3,21,4,1,23,4,43,23,4,12,3,43,5,36,3,45,12,31,3,4,23,41,23,5,53,45,3,7,6,36)
for this vector, the answer should be 5 and 6