たとえば 2000 文字の文字列があります。画面を 70 文字に分割し、最初の 70 文字で試した 70 行ごとに改行を挿入するには、次のようにします。
Dim notes As String = ""
If (clmAck.Notes.Count > 70) Then
notes = clmAck.Notes.Insert(70, Environment.NewLine)
Else
私は今、楽しみのためにこれを書きました:
public static class StringExtension
{
public static string InsertSpaced(this string stringToinsertInto, int spacing, string stringToInsert)
{
StringBuilder stringBuilder = new StringBuilder(stringToinsertInto);
int i = 0;
while (i + spacing < stringBuilder.Length)
{
stringBuilder.Insert(i + spacing, stringToInsert);
i += spacing + stringToInsert.Length;
}
return stringBuilder.ToString();
}
}
[TestCase("123456789")]
public void InsertNewLinesTest(string arg)
{
Console.WriteLine(arg.InsertSpaced(2,Environment.NewLine));
}
これは C# ですが、簡単に翻訳できるはずです。
string notes = "";
var lines = new StringBuilder();
while (notes.Length > 0)
{
int length = Math.Min(notes.Length, 70);
lines.AppendLine(notes.Substring(0, length));
notes = notes.Remove(0, length);
}
notes = lines.ToString();