2016-06-18 33 views
-3

私のjsのコードは次のとおりです。javascriptの文字を部分文字列に変換する方法はありますか?

var str = window.location.hash.substring(window.location.hash.indexOf("/MinPrice") + 1, window.location.hash.lastIndexOf("/")); 
          if (str != "") { 
           window.location.hash = window.location.hash.replace(str, "MinPrice-" + start + "/" + "MaxPrice-" + end); 

          } 
          else { 
           window.location.hash = window.location.hash + "/MinPrice-" + start + "/" + "MaxPrice-" + end + "/"; 

          } 

私の文字列は次のとおりです。==> isAvailable/MinPrice-1501/MaxPrice-4000 /型のAndroid/

または:==>/MinPrice-1501/MaxPrice-4000/isAvailable /タイプのAndroid/

または:==>/isAvailable /タイプのAndroid/MinPrice-1501/MaxPrice-4000

または....

私は上記の文字列からMinPrice-1501/MaxPrice-4000/をサブストリングし、他の文字列で置き換えます。正しいインデックスと

+0

あなたはそれを達成する方法に詳細を提供し、あなたの目標を達成するためにやっている私たちを見る必要があります。これは、自分の問題を解決するための助けが必要な人のためのもので、 "自分のコードを実行する"サービスではない –

+0

''isAvailable/MinPrice-1501/MaxPrice-4000/type-Android /'。split( '/')。 -2).join( '/') ' –

答えて

0

使用substring

"isAvailable/MinPrice-1501/MaxPrice-4000/type-Android/".substring(12,40) 
関連する問題