2017-01-30 8 views
-1

ビジネスロジック層(C#)に慣れていますが、私はjavscriptで錆びています。URLの末尾に追加

"/"で終わらない場合にのみ、文字列の最後に "/"を追加する方が安全でしょうか?

現在、私が持っている:

noteUrl += noteUrl.endsWith("/") ? "" : "/"; 
+4

常に便利である[ 'もし(!noteUrl.endsWith( "/")){...'](https://developer.mozilla.org/ en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)あなたが「より安全」とは何を意味するのか分かりませんが、これは少し良いと思います。 –

答えて

1

真または偽のブール値を返しますendsWith:

  if (entityId != undefined) { 
       noteUrl = window.parent.serverUrl; 
       if (noteUrl.substring(noteUrl.length - 1) != "/") { 
        noteUrl += "/"; 
       } 
関連する問題