It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In the case that there were two text files:
FileA.txt
test
1234
testing
FileB.txt
test
5667
pond
and all occurrences in FileA.txt would be removed from FileB.txt, being output into FileC.txt
So FileC.txt would read:
5667
pond
File.WriteAllLines("FileC.txt",
File.ReadAllLines("FileB.txt").Except(File.ReadAllLines("FileA.txt")));
string fileA, fileB, fileC;
var result = File.ReadAllLines(fileB).Except(File.ReadAllLines(fileA));
File.WriteAllLines(fileC, result);
I'm not sure how your text files are formatted, but you can use StreamReader to load and read through the lines of the text. First, do that to A, add each line to an array, and then filter through the array for each line of B to see if there is a match. If so, remove that line from B before creating C with StreamWriter.
Read about streamreader here. Read about streamwriter here.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I try just an old VB application in c# to convert, while I've encountered this line of code:
Mid(strData, intPosition + 1, intLenght) = strValue
How can it be translated into c#?
You would have to combine Remove and Insert, something like:
strData.Remove(intPosition, intLenght).Insert(intPosition, strValue);
The above assumes that the length of strValue was equal to intLenght. If strValue might be longer, then to replicate the Mid statement, we would need to do:
strData.Remove(intPosition, intLenght)
.Insert(intPosition, strValue.Substring(0, intLenght));
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am new to learning Regex and I am struggling with this basic issue. I want to make sure a string is in a format like: 2000/2001 or 2010/2011.
I tried something like: ^[2000-2900]./.[2000-2900]$ but I know this is wrong!
This would be the very basic:
^\d{4}\/\d{4}$
From the beginning of the string, check if it has 4 digits followed by a "/" (escaped with "\") and another 4 digits to the end of the string.
If you searching for where the entire string must match then:
^\d{4}/\d{4}$
If you are searching for a sub string of a larger string then:
\d{4}/\d{4}
And if you using in C# then remember to wrap it up in a verbatim string like so:
#"^\d{4}/\d{4}$"
#"\d{4}/\d{4}"
I noticed that others are escaping the forward slash but I don't think is necessary but doesn't do any harm if you do.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to find the line in a multi-line string, containing XML, that a given Xpath points to.
In other words, I have a string containing XML. I have a given Xpath, that I want to use to find the exact line line number of the string.
What's the best way to do this?
You might consider using a an XmlTextReader instead. That has LineNumber and LinePosition properties.
The XmlTextReader does have some limited "read until you reach such-and-such a node" properties, but they aren't as sophisticated as those of XPath. Depending on how complex the XPath is, this might or might not work.
I did find a link on the subject here.
You can load the XML from the string into an actual XML class.
XDocument x = XDocument.Parse(yourStringContainingXML);
string contentOfNode = x.Descendants(XName.Get("NameOfTheNode")).First().Value;
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
first of all i know there is many topics talks about this case but not like i want
i want to get the words like Facebook do in mentions names in comments
here is my conditions
1- i want all words start with # char
2- i want all lonely # char
3- i don't want any words that contain '#' like any#hotmail.com
EX: "# this d#y #hmed #nd May# went to play # g#arden"
the result i want is
{"#" , "#hmed" ,"#nd" , "#"}
please notice the second condition i want
thanks
The regex should be /(?:^|\s)(#[^#\s]*)(?=\s|$)/g
[ test: http://ideone.com/1LK80 ]
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have to write an ASCII and have the schemah, each row should be 128 characters, I took string and string and attached so that each field received his position, the test was exactly 128 characters, but in edit.com it's not the right place, I asked how to make the file ascii code? And is there a way to write each string a certain position?
I can not upload the schamah is not in English, also, it i do not speak English and sorry for the mistakes.
thanks in advance
You most likely don't write your file with ASCII encoding - try this:
string myRow =string.Join("", Enumerable.Repeat("A", 128));
string[] rows = new string[] { myRow, myRow };
File.WriteAllLines(#"test.txt", rows, Encoding.ASCII);
This produces a text file where each line is encoded in ASCII (one byte per character) and rows are separated by \r\n characters. The sample produces a file with a size of 260 bytes, 128 bytes for each row plus 2x the two characters for line seperation.