using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
}
List<string> Ls = new List<string>();
void RemoveDuplicatedElements(List<string> elements, bool flag)
{
for (int i = 0; i < elements.Count; i++)
{
int endIndex = elements.LastIndexOf(elements[i]);
//扫描是否有重复字符
if (endIndex != i)
{
//不断扫描,删除,直到除去自身以外全部删除了
do
{
elements.RemoveAt(endIndex);
endIndex = elements.LastIndexOf(elements[i]);
} while (i != endIndex);
//如果彻底删除重复字符,删除自身
if (!flag)
{
elements.RemoveAt(i);
i--;
}
}
}
}
ArrayList JianSuo(string S, ArrayList T)
{
int Flag;
for (int i = 0; i < S.Length; i++)
{
Flag = 1;
for (int j = 0; j < i; j++)
{
try
{
if ((char)T[j] == S[i])
Flag = 0;
}
catch(Exception ex)
{
}
}
if (Flag==1)
{
//T[k++] = S[i];
T.Add(S[i]);
//T.Insert(k++, S[i].ToString());
}
}
return T ;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
ArrayList ListCount=new ArrayList();
ArrayList List=JianSuo("12222366", ListCount);
char[] C = new char[List.Count];
for (int i = 0; i < C.Length; i++)
{
C[i] =(char)List[i];
}
string Str = new string(C);
MessageBox.Show(Str);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string[] Str = new string[6];
Str[0] = "ABC";
Str[1] = "ACC";
Str[2] = "BAC";
Str[3] = "BBC";
Str[4] = "CBC";
Str[5] = "CAC";
char a;
char[] Strr = new char[Str.Length];
for (int i = 0; i < Str.Length; i++)
{
string ST = Str[i];
a = ST[0];
Strr[i]=a;
}
ArrayList ListCount = new ArrayList();
String SG = new string(Strr);
ArrayList List = JianSuo(SG, ListCount);
char[] C = new char[List.Count];
for (int i = 0; i < C.Length; i++)
{
C[i] = (char)List[i];
}
string StrG = new string(C);
MessageBox.Show(StrG);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
comboBox1.Items.Add("ABC");
}
List<string> Ls = new List<string>();
void RemoveDuplicatedElements(List<string> elements, bool flag)
{
for (int i = 0; i < elements.Count; i++)
{
int endIndex = elements.LastIndexOf(elements[i]);
//扫描是否有重复字符
if (endIndex != i)
{
//不断扫描,删除,直到除去自身以外全部删除了
do
{
elements.RemoveAt(endIndex);
endIndex = elements.LastIndexOf(elements[i]);
} while (i != endIndex);
//如果彻底删除重复字符,删除自身
if (!flag)
{
elements.RemoveAt(i);
i--;
}
}
}
}
ArrayList JianSuo(string S, ArrayList T)
{
int Flag;
for (int i = 0; i < S.Length; i++)
{
Flag = 1;
for (int j = 0; j < i; j++)
{
try
{
if ((char)T[j] == S[i])
Flag = 0;
}
catch(Exception ex)
{
}
}
if (Flag==1)
{
//T[k++] = S[i];
T.Add(S[i]);
//T.Insert(k++, S[i].ToString());
}
}
return T ;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
ArrayList ListCount=new ArrayList();
ArrayList List=JianSuo("12222366", ListCount);
char[] C = new char[List.Count];
for (int i = 0; i < C.Length; i++)
{
C[i] =(char)List[i];
}
string Str = new string(C);
MessageBox.Show(Str);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string[] Str = new string[6];
Str[0] = "ABC";
Str[1] = "ACC";
Str[2] = "BAC";
Str[3] = "BBC";
Str[4] = "CBC";
Str[5] = "CAC";
char a;
char[] Strr = new char[Str.Length];
for (int i = 0; i < Str.Length; i++)
{
string ST = Str[i];
a = ST[0];
Strr[i]=a;
}
ArrayList ListCount = new ArrayList();
String SG = new string(Strr);
ArrayList List = JianSuo(SG, ListCount);
char[] C = new char[List.Count];
for (int i = 0; i < C.Length; i++)
{
C[i] = (char)List[i];
}
string StrG = new string(C);
MessageBox.Show(StrG);
}
}
}
string 转换成 Char[]
string ss="abcdefg";
char[] cc=ss.ToCharArray();
Char[] 转换成string
string s=new string(cc);
此外,byte[] 与 string 之间的装换
byte[] bb=Encoding.UTF8.GetBytes(ss);
string s=Encoding.UTF8.GetString(bb);