我需要从文本中加载输入,如下所示:
5, 8, 8, 6, 7, ...
...到一个数组。 (数字用逗号分隔)。
有一种简单的方法吗?
答案 0 :(得分:0)
你为什么要这样做?只需输入一个没有逗号的整数数组。但如果你想,那么这里是如何实现它的。 您可以使用字符数组来保存此类数据。整数数组不行。 您的输入将存储为:
namespace WebApplication1
{
public partial class Upload_page : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpload_Click(object sender, EventArgs e)
{
Response.Write("Working");
string path = "path";
OleDbConnection connection = null;
if (FileUpload1.HasFile)
{
path = string.Concat(Server.MapPath("~/Uploaded Folder/" + FileUpload1.FileName));
FileUpload1.SaveAs(path);
}
path = "C:\\Users\\temp\\Documents\\visual studio 2010\\Projects\\WebApplication1\\WebApplication1\\Uploaded Folder\\TempReport.xls";
try
{
string excelConnectionString = string.Format("Provider=Microsoft.jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0", path);
connection = new OleDbConnection();
connection.ConnectionString = excelConnectionString;
OleDbCommand command = new OleDbCommand("select * from [ISO$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
DbDataReader dr = command.ExecuteReader();
string sqlConnectionString = @"Initial Catalog=CensusTrack;Data Source=CWVQ-2K12E1D;Integrated Security=SSPI;";
// Bulk Copy to SQL Server
SqlBulkCopy bulkInsert = new SqlBulkCopy(sqlConnectionString);
bulkInsert.BulkCopyTimeout = 0;
bulkInsert.BatchSize =0;
bulkInsert.DestinationTableName = "[dbo].[2015_ISO]";
bulkInsert.WriteToServer(dr);
connection.Close();
Response.Write("Completed");
//Label1.Text = "Ho Gaya";
}
catch (Exception obj)
{
connection.Close();
}
}
}
}
因此,要获取输入,首先定义大小为char a[3];
a[0]='1';
a[1]=',';
a[2]='2';
的字符数组a[n]
,然后将输入作为
n
这会将您的数据保存在while(i<n)
{
a[i]=getchar();
i++;
}
数组中
然后,您可以将它们打印为
a[n]={'1' , ',' , '2' , ',' upto n}
您输入的内容为:
i=0;
while(i<n)
{
putchar(a[i]);
i++;
}
,输出结果为:
1,2,3,4,5
偶数编号的索引将包含数字,奇数编号的索引将包含逗号。