Results 1 to 6 of 6

Thread: [RESOLVED] Helping in Convert Code to C#

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Resolved [RESOLVED] Helping in Convert Code to C#

    Hello,

    I to find code in vb but i can't convert it to c#:

    Code:
                  Dim Txt As String = ""
            For Each Nass As String In TextBox1.Text
                Nass = Regex.Replace(Nass, "[Aa]", "[Aa]")
                Nass = Regex.Replace(Nass, "[Bb]", "[Bb]")
                Nass = Regex.Replace(Nass, "[Cc]", "[Cc]")
                Nass = Regex.Replace(Nass, "[Dd]", "[Dd]")
                Nass &= "[ًٌٍَُِّْ]*"
                Txt &= Nass
            Next
    I tried convert code by internet converter this result:

    Code:
                string Txt = "";
                foreach (string Nass in txtBookTitle.Text)
                {
                Nass = Regex.Replace(Nass, "[Aa]", "[Aa]");
                Nass = Regex.Replace(Nass, "[Bb]", "[Bb]");
                Nass = Regex.Replace(Nass, "[Cc]", "[Cc]");
                Nass = Regex.Replace(Nass, "[Dd]", "[Dd]");
                    Nass += "[ًٌٍَُِّْ]*";
                    Txt += Nass;
                }
    But get red line under Nass =

    Please Help me
    Thanks in advance

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Helping in Convert Code to C#

    It looks right to me - what exactly is the error?
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Re: Helping in Convert Code to C#

    Quote Originally Posted by David Anton View Post
    It looks right to me - what exactly is the error?
    I get Error on line 2: "Cannot assign to 'Nass' because it is a 'foreach ineration variable'"

    Code:
         
    1.   For Each Nass As String In TextBox1.Text
       2.         Nass = Regex.Replace(Nass, "[Aa]", "[Aa]")
         3.       Nass = Regex.Replace(Nass, "[Bb]", "[Bb]")
           4.     Nass = Regex.Replace(Nass, "[Cc]", "[Cc]")
             5.   Nass = Regex.Replace(Nass, "[Dd]", "[Dd]")
               6. Nass &= "[ًٌٍَُِّْ]*"
                Txt &= Nass
            Next
    Last edited by waleed_89; Oct 1st, 2011 at 07:30 AM.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Helping in Convert Code to C#

    The error you are getting is pretty explanatory... you can't assign to a for each loop variable.

    In a situation where you need to assign to an existing collection of variables you can use a For loop and the collections indexer.

    In this case you do not appear to need any loop whatsoever as your code appears to be concerned with a single string.
    Code:
                string Txt = txtBookTitle.Text;
                Txt = Regex.Replace(Txt , "[Aa]", "[Aa]");
                Txt = Regex.Replace(Txt , "[Bb]", "[Bb]");
                Txt = Regex.Replace(Txt , "[Cc]", "[Cc]");
                Txt = Regex.Replace(Txt , "[Dd]", "[Dd]");
                Txt  += "[ًٌٍَُِّْ]*";
    W o t . S i g

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Re: [RESOLVED] Helping in Convert Code to C#

    Thank you very much ..

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Re: [RESOLVED] Helping in Convert Code to C#

    Hello,

    The problem solved after changed code Personal.master.cs to this code below:

    Code:
    <%@ Master Language="C#" MasterPageFile="~/Masters/MasterPage.master" AutoEventWireup="True" CodeFile="Personal.master.cs" Inherits="Personal" %> 
     
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
    </asp:Content> 
     
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
          <table style="width:100%;"> 
            <tr> 
                <td class="style5" align="right"> 
                    &nbsp;</td> 
                            <td align="left" width="150"> 
                                <br /> 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                                </td> 
                        </tr> 
                        <tr> 
                            <td align="right" class="style3" valign="top" dir="ltr"> 
                            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> 
        </asp:ContentPlaceHolder> 
                                &nbsp;</td> 
                            <td align="left" valign="top" width="170"> 
                                <br /> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td class="style5" align="left"> 
                                <p style="margin-left: 20px">&nbsp;</p></td> 
                <td> 
                    &nbsp;</td> 
            </tr> 
        </table> 
        <div id="myslideshow"></div> 
    </asp:Content>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width