Click here to Skip to main content
15,887,967 members
Home / Discussions / C#
   

C#

 
GeneralRe: Edit text file using C# Pin
srikanth kamuju29-May-13 23:24
professionalsrikanth kamuju29-May-13 23:24 
GeneralRe: Edit text file using C# Pin
Eddy Vluggen30-May-13 0:17
professionalEddy Vluggen30-May-13 0:17 
GeneralRe: Edit text file using C# Pin
srikanth kamuju30-May-13 1:29
professionalsrikanth kamuju30-May-13 1:29 
GeneralRe: Edit text file using C# Pin
Eddy Vluggen30-May-13 2:13
professionalEddy Vluggen30-May-13 2:13 
JokeRe: Edit text file using C# Pin
AlphaDeltaTheta30-May-13 3:04
AlphaDeltaTheta30-May-13 3:04 
QuestionRe: Edit text file using C# Pin
AlphaDeltaTheta29-May-13 23:12
AlphaDeltaTheta29-May-13 23:12 
AnswerRe: Edit text file using C# Pin
srikanth kamuju29-May-13 23:21
professionalsrikanth kamuju29-May-13 23:21 
AnswerRe: Edit text file using C# Pin
AlphaDeltaTheta29-May-13 23:37
AlphaDeltaTheta29-May-13 23:37 
This is clear,,,
I read in 9th grade of my school that in java and c, ' needs to be escaped as \'. Since c# is a descendant of c, guessing it might be the problem. Try replacing (')s in your code with (\')s. See if it works.

EDIT:
Ignore the above... I figured out the problem
You have used ’ (backquote). It's not a part of standard windows codepage, so it is displayed as "?". Save yout text as UTF8 and write as UTF8 too. Notepad++ is a good tool to convert and edit text files.

Here's some code... how I did it
Java
using System;
using System.Text;
using System.IO;
 
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder newFile = new StringBuilder();
            string temp = "";
            string[] AllLines = File.ReadAllLines("new.txt",Encoding.UTF8);
            string strStart = "<";
            foreach (string strLine in AllLines)
            {
			    Console.WriteLine(strLine);
                if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
                {
                    int fIndex = strLine.IndexOf(strStart);
                    int sIndex = strLine.LastIndexOf("_ags");
                    temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
                    newFile.Append(temp + "\r\n");
                    continue;
                }
                newFile.Append(strLine + "\r\n");
            }
 
            Console.WriteLine(newFile.ToString());
			File.WriteAllText("new2.txt", newFile.ToString(),Encoding.UTF8);
            //Console.ReadKey();
        }
    }

NOTE: your file needs to be encoded in UTF8 or it will result in garbled text!
TIP: Use a regex to replace... Its easy and less complicated.Thumbs Up | :thumbsup:

modified 30-May-13 6:00am.

GeneralRe: Edit text file using C# Pin
Richard MacCutchan29-May-13 23:43
mveRichard MacCutchan29-May-13 23:43 
GeneralRe: Edit text file using C# Pin
AlphaDeltaTheta30-May-13 0:01
AlphaDeltaTheta30-May-13 0:01 
QuestionC# window application Deployment Pin
AjitRaje29-May-13 21:57
AjitRaje29-May-13 21:57 
AnswerRe: C# window application Deployment Pin
Abhinav S29-May-13 22:32
Abhinav S29-May-13 22:32 
QuestionClasses containing Lists Pin
huge_superman29-May-13 21:34
huge_superman29-May-13 21:34 
AnswerRe: Classes containing Lists Pin
Jasmine250130-May-13 9:50
Jasmine250130-May-13 9:50 
QuestionHow to create a setup with two startup object in visual studio 2010? Pin
Viswanathan Ramamoorthy29-May-13 21:14
Viswanathan Ramamoorthy29-May-13 21:14 
AnswerRe: How to create a setup with two startup object in visual studio 2010? Pin
Eddy Vluggen29-May-13 22:00
professionalEddy Vluggen29-May-13 22:00 
AnswerRe: How to create a setup with two startup object in visual studio 2010? Pin
Amol_B30-May-13 20:19
professionalAmol_B30-May-13 20:19 
Questionresize chart in winform using c# Pin
mit6229-May-13 21:00
mit6229-May-13 21:00 
AnswerRe: resize chart in winform using c# Pin
Richard MacCutchan29-May-13 21:03
mveRichard MacCutchan29-May-13 21:03 
QuestionProblems in handling windows forms Pin
Arun kumar Gautam29-May-13 18:58
Arun kumar Gautam29-May-13 18:58 
AnswerRe: Problems in handling windows forms Pin
Richard MacCutchan29-May-13 21:09
mveRichard MacCutchan29-May-13 21:09 
AnswerRe: Problems in handling windows forms Pin
Anna King30-May-13 2:49
professionalAnna King30-May-13 2:49 
AnswerRe: Problems in handling windows forms Pin
Eddy Vluggen30-May-13 2:56
professionalEddy Vluggen30-May-13 2:56 
GeneralTo overcome the load screen flashes with user control and images and controls Pin
Lương Tuấn Anh29-May-13 18:30
Lương Tuấn Anh29-May-13 18:30 
AnswerRe: To overcome the load screen flashes with user control and images and controls Pin
Eddy Vluggen29-May-13 22:33
professionalEddy Vluggen29-May-13 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.