如何替换单词之间的空格以调整此单词的大小 [英] how to replace space between words to size this words
本文介绍了如何替换单词之间的空格以调整此单词的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算术语的大小并将此大小放在文本文件中的术语之前,以替换vb.net中的空格.
how to calculate size of terms and put this size before terms in text file is replace space in vb.net
推荐答案
如果我的超感官感知效果最好,您要在空格长度等于单词之前替换一个空白空间.
例如:
If my extrasensory perception works the best, You want to replace an empty space before the words that the space lenght is equal to the word.
For example:
I am a developer. ==> I am a developer
然后:
Then:
//C#
public string MakeSpace(string text)
{
StringBuilder sentenceBuilder = new StringBuilder();
string[] strings = text.Split((char)32);
foreach (string s in strings)
{
if (string.IsNullOrEmpty(s))
continue;
StringBuilder spaceBuilder = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
spaceBuilder.Append(" ");
}
sentenceBuilder.Append(string.Format("{0}{1}", spaceBuilder.ToString(), s));
}
return sentenceBuilder.ToString();
}
'VB.Net
Public Function MakeSpace(text As String) As String
Dim sentenceBuilder As New StringBuilder()
Dim strings As String() = text.Split(CChar(32))
For Each s As String In strings
If String.IsNullOrEmpty(s) Then
Continue For
End If
Dim spaceBuilder As New StringBuilder()
For i As Integer = 0 To s.Length - 1
spaceBuilder.Append(" ")
Next
sentenceBuilder.Append(String.Format("{0}{1}", spaceBuilder.ToString(), s))
Next
Return sentenceBuilder.ToString()
End Function
这篇关于如何替换单词之间的空格以调整此单词的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文