Converting VbScript functions (Right, Len, IsNumeric, CInt) in C#

后端 未结 4 762
死守一世寂寞
死守一世寂寞 2021-01-29 08:19

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

Function GetNavID(Tit         


        
4条回答
  •  庸人自扰
    2021-01-29 08:49

    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
    

    Translates into:

    if(NavigationId.StartsWith("S")) {
        NavigationId = NavigationId.Substring(1); 
        int navId;
        if(Int32.TryParse(NavigationId, out navId) && navId > 0) {
           // Do what you need to do.
        }
    }
    

    However, you should look into the string manipulation workings of both languages.

提交回复
热议问题