Compare two char arrays


hi 

so im new c# , im trying figur out have problem. want compare 2 char arrays 1 string converted array (textinputtecken) , other 1 char array containing vowels (vokaler). want change vowels in textinputtecken letter i, have way of doing without char array vowels (vokaler). 

            (int = 0; < textinputtecken.length; i++)              {                  if (textinputtecken[i] == 'a' || textinputtecken[i] == 'e' || textinputtecken[i] == 'i' || textinputtecken[i] == 'o' || textinputtecken[i] == 'u' || textinputtecken[i] == 'y' || textinputtecken[i] == 'å' || textinputtecken[i] == 'ä' || textinputtecken[i] == 'ö' || textinputtecken[i] == 'a' || textinputtecken[i] == 'e' || textinputtecken[i] == 'i' || textinputtecken[i] == 'o' || textinputtecken[i] == 'u' || textinputtecken[i] == 'y' || textinputtecken[i] == 'Å' || textinputtecken[i] == 'Ä' || textinputtecken[i] == 'Ö')                  {                      nya = textinput.replace("a", "i").replace("e", "i").replace("o", "i").replace("u", "i").replace("y", "i").replace("å", "i").replace("ä", "i").replace("ö", "i").replace("a", "i").replace("e", "i").replace("i", "i").replace("o", "i").replace("u", "i").replace("y", "i").replace("Å", "i").replace("Ä", "i").replace("Ö", "i");                      txtconvert.text = nya;                      total++;                      lblvokalantal.text = total.tostring() + " vokaler";                  }              }

i have tried doing doesnt work. how can work?

            char[] vokaler = new char[] { 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'y', 'y', 'å', 'Å', 'ä', 'Ä', 'ö', 'Ö' };                (int = 0; < textinputtecken.length; i++)              {                  if (textinputtecken[i] == vokaler[i])                  {                      nya = textinput.replace("a", "i").replace("e", "i").replace("o", "i").replace("u", "i").replace("y", "i").replace("å", "i").replace("ä", "i").replace("ö", "i").replace("a", "i").replace("e", "i").replace("i", "i").replace("o", "i").replace("u", "i").replace("y", "i").replace("Å", "i").replace("Ä", "i").replace("Ö", "i");                      txtconvert.text = nya;                      total++;                      lblvokalantal.text = total.tostring() + " vokaler";                  }              }

or using replace():

namespace consolecs {     using system;      public class program     {         static void main(string[] args)         {             char[] vokaler = new char[] { 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'u', 'u', 'y', 'y', 'å', 'Å', 'ä', 'Ä', 'ö', 'Ö' };             char[] textinputtecken = new char[] { 'a', 'b', 'c', 'd', 'e' };             string dummy = new string(textinputtecken);                         (int v = 0; v < vokaler.length; v++)             {                 dummy= dummy.replace(vokaler[v], 'x');             }              textinputtecken = dummy.tochararray();             console.writeline("result {0}.", new string(textinputtecken));              console.writeline("done.");             console.readline();         }     } }

some minor additions:
- not nessesary translate string char[]. indexers in .net class scope functions , string has them. can use indexers on string itself. other way around nessesary. of course string have constructor takes char[] input, easy.

- using non-english characters. such, normalisation might issue when doing this. might issues far creating array string. make part or run issues:
https://msdn.microsoft.com/en-us/library/8eaxk1x2.aspx


remember mark helpfull answers helpfull , close threads marking answers.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user