我有字符串“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
答案 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));