在 C# 中转换 VbScript 函数(Right、Len、IsNumeric、CInt) [英] Converting VbScript functions (Right, Len, IsNumeric, CInt) in C#

查看:33
本文介绍了在 C# 中转换 VbScript 函数(Right、Len、IsNumeric、CInt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再说一次,我在 VbScript 中得到了以下代码,请您建议什么是 C# 中的等效代码.

Again, I have got below code in VbScript, can you please suggest what will be equivalent code in C#.

Function GetNavID(Title)
    getNavID=UCase(Left(Title, InStr(Title, ". ") -1))
End Function

我已经从上一个问题中获得了上述代码更改,即

I have already got above code change from my last question i.e.

public static string GetNavID(string Title)
{
    int index = Title.IndexOf(". ");
    return Title.Substring(0, index - 1).ToUpper();
} 

现在我也想在 c# 中转换下面的代码,因为有很多 VBScript 函数,所以很困惑.

Now I want to convert below code also in c#,as there are lots of VBScript functions, so getting confused.

Dim NavigationId 'As String

NavigationId = GetNavID(oPage.Title)

' Is it a subnavigation member page ?
If Left(NavigationId, 1) = "S" Then
    NavigationId = Right(NavigationId, Len(NavigationId) - 1)           
    If IsNumeric(NavigationId) Then
        ' Its a subnavigation non-index page "Sxxx"
        If CInt(NavigationId) > 0 Then

        End If
    End If
End If  

请推荐!!

推荐答案

尝试:

if (NavigationId.StartsWith("S"))
{
    NavigationId = NavigationId.Substring(1);
    int id;
    if (int.TryParse(NavigationId,out id))
    {
        if (id > 0)
        {
        }
    }
}

这篇关于在 C# 中转换 VbScript 函数(Right、Len、IsNumeric、CInt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆