Results 1 to 6 of 6

Thread: Condition For Copying A File Not Working

  1. #1
    Join Date
    Nov 2009
    Posts
    680

    Condition For Copying A File Not Working

    Hello, My conditions seem not work and I can not understand why. I tried the operator "|" and "| |" without success, here is the snippet of C#:

    Code:
    string[] str = File.ReadAllLines(@ ". / myfile");
                    foreach (string newLine in str)
                    {
                        if (newLine.Contains(deleteName + ";"))
                        {
                            string[] one = newLine.Split('=');
                            delete = Regex.Replace(one[0], "[a-zA-Z]", "");
                        }
                        if (delete! = "")
                        {
                            if (! newLine.Contains("string" + Delete) | |! NewLine.Contains("TEST2" + Delete) | |! NewLine.Contains("TEST" + Delete))
                            {
                                sw.Write(newLine);
                                sw.Write(Environment.NewLine);
                            }
     
                        }
     
                    }
    sw.Close();
    How to solve this problem?

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Condition For Copying A File Not Working

    Hello, I think you are getting this problem due to the problem of the code. You need to check the code of your program by using the below code :

    Code:
    remove.Equals(string.Empty);
    or
    Code:
    remove.Length==0

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Condition For Copying A File Not Working

    If you declare as given below then it will solve your problem.
    Code:
    string remove =String.Empty;
    I have checked it. If you make use of the above code then you don't get the problem. I think you must read the books below:
    • Programming Microsoft Visual C# 2008: The Language
    • Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition (Windows.Net)

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Condition For Copying A File Not Working

    Hey, I think you must need to make use of the code below. I have created it by modifying the code of your. So, make use of it and solve the problem of your.
    Code:
    private void delete_BTN_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("Are you sure you want to delete this entry: \ r\ n" + EntryName, "", butoon.OkCancel) == DialogResult.OK)
                {
                    string[] str = File.ReadAllLines(@ ". / file.ini");
                    string cancel = theList_CBOX.SelectedItem.ToString();
                    int j = 0;
                    string[] test = new string[(theList_CBOX.Items.Count)-1];
                    StreamWriter writer = new StreamWriter(Environment.ExpandEnvironmentVariables("% temp%") + @ "\ temp"); 
                    foreach (string newLine in str)
                    {
                        if (newLine.Contains(cancel + ";"))
                        {
                            string[] str1 = newLine.Split('=');
                            remove = Regex.Replace(str1[0], "[a-zA-Z]", "");
                        }                    
                        if (remove! = "")
                        {
                            if (! Regex.IsMatch(newLine, "abc" + Remove) | |! Regex.IsMatch(newLine, "def" + Remove) | |! Regex.IsMatch(newLine, "ghi" + Remove))
                            {
                                writer.Write(newLine);
                                writer.Write(Environment.NewLine);
                            } 
                        } 
                    }
                    writer.Close();
                    File.Delete(inipath);
                    File.Move(Environment.ExpandEnvironmentVariables("% temp%") + @ "\ temp", @ ". / file.ini");
                }
            }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Condition For Copying A File Not Working

    I think you nee to make use of the code below if your Contition is either a negative
    Code:
    if (! Regex.IsMatch(newLine, "Test" + Delete) 
        & &! Regex.IsMatch(newLine, "Anotest" + Delete) 
        & &! Regex.IsMatch(newLine, "nothing" + Delete))
    But, if your condition is a positive condition then use the code below:

    Code:
    if (Regex.IsMatch(newLine, "Test" + Delete) 
        | | Regex.IsMatch(newLine, "Anotest" + Delete) 
        | | Regex.IsMatch(newLine, "nothing" + Delete))

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Condition For Copying A File Not Working

    Instead of this below code:
    Code:
    if (! Regex.IsMatch(newLine, "item" + check) | |! Regex.IsMatch(newLine, "meti" + check) | |! Regex.IsMatch(newLine, "key" + check))
    You need to make use of the code below:
    Code:
    if (!(Regex.IsMatch(newLine, "item" + check) | | Regex.IsMatch(newLine, "meti" + check) | | Regex.IsMatch(newLine, "key" + check)))
    It will solve your all problem and you will get the code to use.

Similar Threads

  1. Intel RST service not in working condition
    By triop in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 27-10-2010, 09:39 PM
  2. Mic of MacBook Air is not in the working condition.
    By Dakshina in forum Portable Devices
    Replies: 3
    Last Post: 26-10-2010, 06:04 AM
  3. Replies: 3
    Last Post: 27-11-2008, 01:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,698,419.30696 seconds with 16 queries