textbox显示数组

kouyu 2006-09-11 02:15:18
有两个textbox:textbox1和textbox2.
textbox1输入数字(2,1,4,3,5,7,8,6)后,在textbox2显示排序后的值(1,2,3,4,5,6,7,8).如何实现
请各位指教.还有textbox如何显示排序后的数组?
...全文
813 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kouyu 2006-09-13
  • 打赏
  • 举报
回复
我把我的这段发出来,大家帮我看下问题在哪?就是显示不了
public class ChildForm
{
private void button7_Click(object sender, EventArgs e)
{
string t12number = textBox12.Text.ToString().Trim();
string[] str12a = t12number.Split(',');
int[] int12a = new int[str12a.Length];
for (int i = 0; i < str12a.Length; i++)
{
int12a[i] = int.Parse(str12a[i]);
}

int[] int12b = p.maopao(int12a);
string[] str12b = new string[int12b.Length];
for (int i = 0; i < int12b.Length; i++)
{
str12b[i] += int12b[i].ToString()+",";
}
textBox13.Text = str12b.ToString();
}
}

public class x
{
public int[] maopao(int[] a)
{
int[] int12 = a;
for (int i = 1; i < int12.Length; i++)
{
for (int j = 0; j < int12.Length - 1; j++)
{
if (int12[j] > int12[j + 1])
{
int temp = int12[j];
int12[j + 1] = int12[j];
int12[j] = temp;
}
}
}
return int12;
}
}
namhyuk 2006-09-12
  • 打赏
  • 举报
回复
ar.Sort();是以字符形式排序的吧?
如果有1,22,11三个数,排序后的样子会是什么?是这个问题想要的结果吗?
tshark 2006-09-12
  • 打赏
  • 举报
回复
楼上说的对...是按字符排序.这点我也是才知道
tshark 2006-09-11
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ArrayList ar = new ArrayList();
string str1 = this.textBox1.Text;
string[] strs = str1.Split(',');
foreach (string elem in strs)
{
ar.Add(elem);
}
string str2 = "";
ar.Sort();

for(int nIndex=0;nIndex<ar.Count;nIndex++)
{
str2+=ar[nIndex]+",";
}
this.textBox2.Text = str2;
}
}
}

完全满足你的要求.这是我的一个作业题呵呵~做了好多遍了
jrjjrj001 2006-09-11
  • 打赏
  • 举报
回复
上厕所的时候顺便写完,写得太急,没有优化
string[] aaa=textBox1.Text.Split(",".ToCharArray());

ArrayList list1=new ArrayList();
foreach(string a in aaa)
{
list1.Add(a);
}
int i=0;
int index1;
int index2;
int j=0;

ArrayList list2=new ArrayList();
ArrayList list3=new ArrayList();
list3.AddRange(list1);
int b=list1.Count;

try
{
while(list2.Count!=b)
{
foreach(string ss1 in list1)
{
index1=Convert.ToInt32(ss1);
foreach(string ss2 in list3)
{
index2=Convert.ToInt32(ss2);
if(index1<index2)
{
j=0;
break;
}
else
{
j=1;
}
}
if(j==1)
{
list2.Add(index1.ToString());
list3.Remove(index1.ToString());
}
}
list1.RemoveRange(0,list1.Count);
list1.AddRange(list3);
}
}
catch(Exception excpt)
{
MessageBox.Show(excpt.Message);
}
foreach(string ss3 in list2)
{
textBox2.Text+=ss3+",";
}
int index3;
index3=textBox2.Text.LastIndexOf(",");
textBox2.Text=textBox2.Text.Substring(0,index3);
www_123du_com 2006-09-11
  • 打赏
  • 举报
回复
int[] arrInt = new int[10];
....
string[] arrStr = new string[arrInt.Length];
for (int i=0; i<arrStr.Length; i++)
{
arrStr[i] = arrInt[i].ToString();
}
string all = string.Join(",",arrStr); //textBox.Text = all;
kouyu 2006-09-11
  • 打赏
  • 举报
回复
我的问题只是说:假设我已经排好了{1,2,3,4,5,6,7,8},那么怎么样让textbox2里面显示排好的数组.也就是怎么把int数组转换成string数组后,显示出来.而且能不能各个数据项也是分开的,用符号间隔开的.我试了用.tostring();但是没有实现
smallAss_bigAss 2006-09-11
  • 打赏
  • 举报
回复
我本來是搞perl的,對c#不是很懂,我覺得用正則表達式很容易就把問題解決了
ParadiseX 2006-09-11
  • 打赏
  • 举报
回复
string [] split = text1.Text.Split(new Char [] {','});

通过上面这个步骤,你的TEXT1中的内容已经被分割到一个个字符串数组了
然后你通过选择排序,冒泡排序,希尔排序等等等的排序算法对其进行一下排序,最后写到TEXT2里就好了(当然排序算法也不用自己些,加入到一个ARRAYLIST,然后实现一个COMPARTOR,就可以了)
zhoulin777 2006-09-11
  • 打赏
  • 举报
回复
你是在textbox1,输入一个数字吧!
在textbox1的change事件里面,
string s = tbxbox2.text;
string s_temp = tbxbox1.text;
if(!s.Equals(""))
{
string [] a = s.split(",");
}
然后对数组a排序,将s_temp转换成数字,放进去。再在textbox2里面显示出来,应该就好了
bestshl 2006-09-11
  • 打赏
  • 举报
回复
输入的时候有逗号吗
fd7893 2006-09-11
  • 打赏
  • 举报
回复
数组转成String不就行了

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧