Wuu Posted June 27, 2009 Report Posted June 27, 2009 Pēc pieprasījuma no php atnāk šādas struktūras strings "recive" 9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas 9 - ID http - adrese un beigas - nosaukums var id = recive.split(" ",3); Sākuma domāju ka tikšu galā ar parastu split ,bet nesanāk un tas arī ir loģiski. Kā man atdalīt "Kaut kas" ? Quote
0 cucumber Posted June 27, 2009 Report Posted June 27, 2009 Ka ta $string = '9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas'; list($id,$url,$com) = explode(' ', $string, 3); Citāts nebija vajadzīgs Quote
0 Aleksejs Posted June 27, 2009 Report Posted June 27, 2009 Cucumber, jautājums ir par JavaScript ;) Quote
0 cucumber Posted June 27, 2009 Report Posted June 27, 2009 (edited) Sorry, my false. Sadalu nosaukumi baigi nepamanami. Ideja tak nemainas. var longstring = "Most of the time Amrit is confused — OK, not most of the time"; var brokenstring = longstring.split(" ",3); brokenstings, dalisies aiz komatiem Edited June 27, 2009 by cucumber Quote
0 Wuu Posted June 27, 2009 Author Report Posted June 27, 2009 (edited) var longstring = "Most of the time Amrit is confused — OK, not most of the time"; var brokenstring = longstring.split(" ",3); alert(brokenstring[2]); Tu manu postu neizlasīji :( Tur tak tāds pats variants atgriež tik "the" Edited June 27, 2009 by Wuu Quote
0 cucumber Posted June 27, 2009 Report Posted June 27, 2009 Kaut kas dabut shita, ja atstarpju vairak par 3 nebus. var longstring = "9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas"; var brokenstring = longstring.split(" "); var totChars = 0; for ( i = 0; i < 3; i++) { totChars += brokenstring[i].length; } alert(longstring.substring(totChars-2)); Quote
0 Aleksejs Posted June 27, 2009 Report Posted June 27, 2009 Varbūt šādi: var longstring = "Most of the time Amrit is confused — OK, not most of the time"; var brokenstring = longstring.split(" "); for(x=3;x<brokenstring.length;x++){ brokenstring[2] = brokenstring[2] + " " + brokenstring[x]; } Vai arī šādi: var longstring = "Most of the time Amrit is confused — OK, not most of the time"; brokenstring = longstring.slice(0,longstring.indexOf(" ",1)).split(" ");//Neesmu pārliecināts, vai iekš indexOf vajag 1 vai 2 brokenstring[] = longstring.slice(longstring.indexOf(" ",1)+1); Quote
0 Wuu Posted June 27, 2009 Author Report Posted June 27, 2009 Tas īsti neder ,es domāju varbūt to "space" aizstāt ar kādu specifisku simbolu ,un visas problēmas būtu atrisinātas. Tik kādu lai izvēlas? Quote
0 v3rb0 Posted June 27, 2009 Report Posted June 27, 2009 var s="9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas", id=false, url=false, name=false; if(m = s.match(/(\d+)\s+(.*?)\s+(.*)/)) { name = m.pop(); url = m.pop(); id=m.pop(); } alert(id + "\n" + url + "\n" + name); ? Quote
0 Wuu Posted June 27, 2009 Author Report Posted June 27, 2009 Der gan dabūju pie dzīvības ,paldies :) Quote
Question
Wuu
Pēc pieprasījuma no php atnāk šādas struktūras strings "recive"
9 - ID
http - adrese
un beigas - nosaukums
Sākuma domāju ka tikšu galā ar parastu split ,bet nesanāk un tas arī ir loģiski.
Kā man atdalīt "Kaut kas" ?
10 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.