c# - Searching Specific Data From a File -
I have a file that contains text and some numbers. I just want to remove points from it. How do I go about it? ??
I tried to use all those split things but there is no luck yet. My file is like this:
AT + CMGL = "AL" + CMGL: 5566, "REC READ", "UFO" Dear Customer, Your DAY_BUCKET subscription on 02/05/09 Let me tell you how to remove SMS number + 923466666666 from this file so that I can get another file from them: CMGR: 5565, "REC READ", "+ 923466666666"
I can put in or text box.
Thanks
How big is the file? If the file is under some megabytes in size, then I recommend using a compiled regular expression to load the file contents into a string and remove the matches.
Here's a quick example:
Rexax number extractor = new regedx ("[0- 9] {7,16}", regedx option. /// & lt; Summary & gt; /// Number extracts between seven and sixteen digits from the target file /// Example number to be removed: + 923466666666 /// & lt; / Summary & gt; /// & lt; Param name = "targetfilepath" & gt; & Lt; / Param & gt; /// & lt; Returns & gt; List of matching numbers & lt; / Returns & gt; Private Inenimbable & lt; Ulong & gt; ExtractLongNumbersFromPile (String TargetFilePath) {If (String.IsNullOrEmptE (TargetFilePath) Throw New ArgumentException ("TargetFilePath is empty or empty.", "TargetFilePath"); If (File.Exists (TargetFilePath) == incorrect) Throw new exception ("target file does not exist!"); FileStream TargetFileStream = null; Streamerminer GoalFileTermreader = Faucet; String file resource = ""; & Lt; Ulong & gt; Return list = new list & lt; Ulong & gt; (); {Try TargetFileStream = New FileStream (TargetFilePath, FileMode.Open); TargetFileStreamReader = New StreamReader (TargetFileStream); FileContents = TargetFileStreamReader.ReadToEnd (); MatchCollection matches = number extractor. Matches (file resource); Foreign matches (in match-match matches) {ReturnList.Add (System.Convert.tUUnt64 (CurrentMatch.Value)); }} Hold (Exception Pre) {// Your Logging, etc ...} Finally {if (TargetFileStream! = Null) {TargetFileStream.Close (); TargetFileStream.Dispose (); } If (TargetFileStreamReader! = Tap) {TargetFileStreamReader.Dispose (); }} Return (IEnumerable & lt; ulong & gt;) Retirement Listener; } Sample usage:
list & lt; Ulong & gt; Number = (list & lt; ulong & gt;) ExtractLongNumbersFromFile (@ "v: \ TestExtract.txt");
Comments
Post a Comment