本文介绍了100个字符后在网格视图中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个1000个字符的单词.我想在网格视图中以100个字符间隔.
i have one words with 1000 character .i want to space in grid view after 100 character .
推荐答案
for (var i = 0; i < objDt.Rows.Count; i++)
{
using (var objOrderBo = new OrderBO())
{
objOrderBo.AgentName = Truncate(objDt.Rows[i]["agentname"].ToString(), 20);
objExporterData.Add(objOrderBo);
}
}
这是您的截断功能
And this is your truncate funtion
public static string Truncate(string input, int characterLimit)
{
var finaloutput = string.Empty;
// Check if the string is longer than the allowed amount
// otherwise do nothing
var words = input.Split(' ');
foreach (var word in words)
{
string output;
if (word.Length > characterLimit && characterLimit > 0)
{
output = AddBy(word, " ", characterLimit);
}
else
{
output = word;
}
if (finaloutput == "")
{
finaloutput = output;
}
else
{
finaloutput += " " + output;
}
// Finally, add the "..."
// output += "...";
}
return finaloutput;
}
protected static string AddBy(string inString, string insert, int location)
{
var sb = new System.Text.StringBuilder();
var i = 0;
while (i < inString.Length)
{
var getMe = location;
if (i + location > inString.Length)
getMe = (inString.Length - i);
sb.Append(inString.Substring(i, getMe));
sb.Append(insert);
i = i + location;
}
return sb.ToString();
}
这篇关于100个字符后在网格视图中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!