按设定金额拆分字符串,并将变量分配给拆分

时间:2016-03-06 16:06:52

标签: javascript jquery html string slice

我有字符串“hello123”,并希望将其拆分为“地狱”和“o123”,但我不知道如何。另外,我想将import AVFoundation import UIKit class ViewController: UIViewController { @IBOutlet weak var mainButton1: UIButton! var arrayOfSounds = ["sound1", "sound2", "sound3", "sound4"] var audioPlayer : AVAudioPlayer? func setupAudioPlayer(file: NSString, type: NSString){ let path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String) let url = NSURL.fileURLWithPath(path!) do { try audioPlayer = AVAudioPlayer(contentsOfURL: url) } catch { print("Player not available") } } @IBAction func buttonPressed(sender: AnyObject){ let range: UInt32 = UInt32(arrayOfSounds.count) let number = Int(arc4random_uniform(range)) self.setupAudioPlayer(arrayOfSounds[number], type: "wav") self.audioPlayer?.play() } } 指定为等于“地狱”,将firstPart指定为等于“o123”。非常感谢任何帮助。

secondPart

4 个答案:

答案 0 :(得分:1)

string EncodeParam(string param)
{
     var s = WebUtility.UrlEncode(param);
     return s.Replace("+", "%20");
}

答案 1 :(得分:0)

var str = "hello123";
var firstPart = str.substr(4); // => "Tabs1"
var secondPart = str.substr(id.length - 4); // => "1"

答案 2 :(得分:0)

我不建议这样做,为此使用窗口对象。



var str = 'hello123';

str.match(/.{4}/g).forEach(function (a) {
    window[a] = a;
});

document.write(hell + o123);




答案 3 :(得分:0)

var str = 'hello12312312bhfbdhfbh13h123bkbkfbk123bk123bk213kj';

document.write(str.match(/.{4}/g));