将文本转换为数字

时间:2015-08-12 09:31:30

标签: excel vba excel-vba

我不知道为什么这段代码不起作用..我想把文字转换为数字..它没有给我任何错误但是它没有工作

String strpath="/var/nagios.log";
ReversedLinesFileReader fr = new ReversedLinesFileReader(new File(strpath));
String ch;
int time=0;
String Conversion="";
do {
    ch = fr.readLine();
    out.print(ch+"<br/>"); 
} while (ch != null);
fr.close();

3 个答案:

答案 0 :(得分:1)

这可能是因为您可能有不需要的前导或尾随空格而无法进行比较。此外,代码末尾不需要Exit Function。它将以任何方式退出:)

试试这个

Public Function ConvertCOMPLEXITYToNumber(ByVal chain As String) As Integer
    Dim Num As Integer

    Select Case Trim(chain)
        Case "1 - Très difficile": Num = 1
        Case "2 - Difficile": Num = 2
        Case "3 - Modérée": Num = 3
        Case "4 - Facile": Num = 4
        Case Else: Num = 0
    End Select

    ConvertCOMPLEXITYToNumber = Num
End Function

答案 1 :(得分:0)

If IsNumeric(Left(Trim(chain),1)) Then
    ConvertCOMPLEXITYToNumber = Left(Trim(chain),1)
Else
    ConvertCOMPLEXITYToNumber = 0
End If

答案 2 :(得分:0)

在这里,我的方法是:

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(5)-[layer(==20)]-(5)-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(layer)]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(5)-[layer(==20)]-(0)-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(layer)]];