如何在小数点(。)之前得到左边字符的文本长度? [英] How can I get the textlength of left characters before decimal point(.)?
本文介绍了如何在小数点(。)之前得到左边字符的文本长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得小数点前的左侧字符的文本长度(。)?
示例Run1:
Textbox7.text = 9.48 03/21/2014
预期结果= 0.48 03/21/2014
样本运行2:
Textbox7.text = 9.8 03/21/2014
预计结果= 09.08 03/21/2014
如果Val(TextBox7.Text.Trim.Split(。)(1).Length = 1)那么
TextBox7.Text =0+ TextBox7.Text
结束如果
How can I get the textlength of left characters before decimal point(.)?
Sample Run1:
Textbox7.text = 9.48 03/21/2014
Expected Result = 0.48 03/21/2014
Sample Run2:
Textbox7.text = 9.8 03/21/2014
Expected Result = 09.08 03/21/2014
If Val(TextBox7.Text.Trim.Split(".")(1).Length = 1) Then
TextBox7.Text = "0" + TextBox7.Text
End If
推荐答案
这是你问题的解决方案出现在标题中。请参阅以下示例和注释中的说明:
This is the solution to your question appeared in the title. See the following example and explanation in comments:
Imports System
Public Module Module1
Public Sub Main()
DIM str as string ="1253.45"
' Find the index position of . in str
DIM pos as Integer = str.IndexOf(".")
' Find the left part of the str till .
DIM leftStr as string = str.Substring(0, pos)
' Get the length of the left part
Console.WriteLine(leftStr.length)
End Sub
End Module
这篇关于如何在小数点(。)之前得到左边字符的文本长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文