質問者
textboxの文字列挿入

質問
-
私は、Visual-C#初心者なのですが、
textboxへの文字列挿入がうまく出来ず困っています。
(例)textbox1の文字列を以下のように置換(挿入)したいのですが。
置換前(挿入前)のtextbox1
123.456.789.012
234.567.890.123
ab.efg.hij.klm
以下割愛
置換後(挿入後)のtextbox1:以下の様に処理がしたいですが・・・
(aa)123.456.789.012
(aa)234.567.890.123
(aa)abc.efg.hij.klm
textbox1.text.insert(0,"(aa)")で処理をすると、
(aa)123.456.789.012
234.567.890.123
ab.efg.hij.klm
以上のようになってしまいます。
行数とかは特にきまっておらず、何行あるかはわかりません。
文字列も、その都度かわってきます。
全ての行先頭に(aa)を挿入したいだけなのですが・・・
スキルが初心者レベルなもので。。
かなり初心者レベルの質問かと思いますが、
ご教授の程よろしくお願いいたします。
すべての返信
-
じゃんぬねっと さんのを参考にソースを書いてみました。もし見ることがあったら使ってください。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace helper3cs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 2; i++)
{
textBox2.Text += "(aa)"+textBox1.Lines[i]+"\r\n";
}
}private void Form1_Load(object sender, EventArgs e)
{
textBox1.Multiline = true;
textBox1.Height = textBox1.Height * 3;
textBox1.ScrollBars = ScrollBars.Vertical;
textBox2.Multiline = true;
textBox2.Height = textBox1.Height * 3;
textBox2.ScrollBars = ScrollBars.Vertical;
string [] saray=new string[3];
saray[0]="123.456.789.012\r\n";
saray[1]="234.567.890.123\r\n";
saray[2]="ab.efg.hij.klm\r\n";
for (int i = 0; i <= 2; i++)
{
textBox1.Text += saray[i];// +"\n";
}
}
}
}