Actionscript 3 - 字符串用 MML 替换字符?
首先:我是编程新手。如果您选择帮助我,请详细说明。
我想做的是首先从硬编码推文中删除所有特殊字符。我接下来要做的就是使用 MML(音乐宏语言)将每个字母转换为特定的音调。
当我尝试替换后通过声音库 sion 播放推文时,我只听到了五个音调。我做错了什么?我猜这很简单,但我什么都不知道。
我正在 FDT 中编写 Actionscript 3,这对我来说是非常新的,正则表达式也是如此。
public function translateTweet() {
var myPattern:RegExp = /[~%&\\;:"',<>?#]+/g;
var tweet : String = "@cupofjoakim AN EXAMPLE string! :D #hi11expo";
tweet = tweet.replace(myPattern, " ");
// maybe i could take away a lot of the code for removing the
// special characters? dont dare to do it now, but still.
myPattern = /[~%&\\;:"',<>?#]+/g;
trace(tweet.replace(/[~%&\\;:"',<>?#]+/g, ""));
// Now that Special characters should be gone, let's translate the rest!
trace(tweet.replace(/\s/g, "r4"));
trace(tweet.replace(/a/g, "o4c"));
trace(tweet.replace(/b/g, "o4d"));
trace(tweet.replace(/c/g, "o4e"));
trace(tweet.replace(/d/g, "o4f"));
trace(tweet.replace(/e/g, "o4g"));
trace(tweet.replace(/f/g, "o4a"));
trace(tweet.replace(/g/g, "o4b"));
trace(tweet.replace(/h/g, "o5c"));
trace(tweet.replace(/i/g, "o5d"));
trace(tweet.replace(/j/g, "o5e"));
trace(tweet.replace(/k/g, "o5f"));
trace(tweet.replace(/l/g, "o5g"));
trace(tweet.replace(/m/g, "o5a"));
trace(tweet.replace(/n/g, "o5b"));
trace(tweet.replace(/o/g, "o4c"));
trace(tweet.replace(/p/g, "o4d"));
trace(tweet.replace(/q/g, "o4e"));
trace(tweet.replace(/r/g, "o4f"));
trace(tweet.replace(/s/g, "o4g"));
trace(tweet.replace(/t/g, "o4a"));
trace(tweet.replace(/u/g, "o4b"));
trace(tweet.replace(/v/g, "o5c"));
trace(tweet.replace(/w/g, "o5d"));
trace(tweet.replace(/x/g, "o5e"));
trace(tweet.replace(/y/g, "o5f"));
trace(tweet.replace(/z/g, "o5g"));
trace(tweet.replace(/A/g, "CAPS_A"));
trace(tweet.replace(/B/g, "CAPS_B"));
trace(tweet.replace(/C/g, "CAPS_C"));
trace(tweet.replace(/D/g, "CAPS_D"));
trace(tweet.replace(/E/g, "CAPS_E"));
trace(tweet.replace(/F/g, "CAPS_F"));
trace(tweet.replace(/G/g, "CAPS_G"));
trace(tweet.replace(/H/g, "CAPS_H"));
trace(tweet.replace(/I/g, "CAPS_I"));
trace(tweet.replace(/J/g, "CAPS_J"));
trace(tweet.replace(/K/g, "CAPS_K"));
trace(tweet.replace(/L/g, "CAPS_L"));
trace(tweet.replace(/M/g, "CAPS_M"));
trace(tweet.replace(/N/g, "CAPS_N"));
trace(tweet.replace(/O/g, "CAPS_O"));
trace(tweet.replace(/P/g, "CAPS_P"));
trace(tweet.replace(/Q/g, "CAPS_Q"));
trace(tweet.replace(/R/g, "CAPS_R"));
trace(tweet.replace(/S/g, "CAPS_S"));
trace(tweet.replace(/T/g, "CAPS_T"));
trace(tweet.replace(/U/g, "CAPS_U"));
trace(tweet.replace(/V/g, "CAPS_V"));
trace(tweet.replace(/W/g, "CAPS_W"));
trace(tweet.replace(/X/g, "CAPS_X"));
trace(tweet.replace(/Y/g, "CAPS_Y"));
trace(tweet.replace(/Z/g, "CAPS_Z"));
trace(tweet.replace(/å/g, "o4c"));
trace(tweet.replace(/Å/g, "o4c2"));
trace(tweet.replace(/ä/g, "o4c"));
trace(tweet.replace(/Ä/g, "o4c2"));
trace(tweet.replace(/á/g, "o4c"));
trace(tweet.replace(/Á/g, "o4c2"));
trace(tweet.replace(/à/g, "o4c"));
trace(tweet.replace(/À/g, "o4c2"));
trace(tweet.replace(/é/g, "o4g"));
trace(tweet.replace(/É/g, "o4g2"));
trace(tweet.replace(/è/g, "o4g"));
trace(tweet.replace(/È/g, "o4g2"));
trace(tweet.replace(/ë/g, "o4g"));
trace(tweet.replace(/Ë/g, "o4g2"));
trace(tweet.replace(/ú/g, "o4b"));
trace(tweet.replace(/Ú/g, "o4b2"));
trace(tweet.replace(/ù/g, "o4b"));
trace(tweet.replace(/Ù/g, "o4b2"));
trace(tweet.replace(/ü/g, "o4b"));
trace(tweet.replace(/Ü/g, "o4b2"));
trace(tweet.replace(/í/g, "o5d"));
trace(tweet.replace(/Í/g, "o5d2"));
trace(tweet.replace(/ì/g, "o5d"));
trace(tweet.replace(/Ì/g, "o5d2"));
trace(tweet.replace(/ï/g, "o5d"));
trace(tweet.replace(/Ï/g, "o5d2"));
trace(tweet.replace(/ó/g, "o4c"));
trace(tweet.replace(/Ó/g, "o4c2"));
trace(tweet.replace(/ò/g, "o4c"));
trace(tweet.replace(/Ò/g, "o4c2"));
trace(tweet.replace(/ö/g, "o4c"));
trace(tweet.replace(/Ö/g, "o4c2"));
}
First of all: I'm new to programing. Please be detailed if you choose to help me.
What i'm trying to do is to first of all remove all special characters from a hard coded tweet. What I want to do after is to convert each letter into a specific tone, using MML (Music Macro Language).
When i play the tweet via the sound library sion after my attempted replacing i only get five tones through. What am I doing wrong? I'm guessing it's simple, but I don't know anything.
I'm coding Actionscript 3 in FDT, which is all very new to me, as is regexp.
public function translateTweet() {
var myPattern:RegExp = /[~%&\\;:"',<>?#]+/g;
var tweet : String = "@cupofjoakim AN EXAMPLE string! :D #hi11expo";
tweet = tweet.replace(myPattern, " ");
// maybe i could take away a lot of the code for removing the
// special characters? dont dare to do it now, but still.
myPattern = /[~%&\\;:"',<>?#]+/g;
trace(tweet.replace(/[~%&\\;:"',<>?#]+/g, ""));
// Now that Special characters should be gone, let's translate the rest!
trace(tweet.replace(/\s/g, "r4"));
trace(tweet.replace(/a/g, "o4c"));
trace(tweet.replace(/b/g, "o4d"));
trace(tweet.replace(/c/g, "o4e"));
trace(tweet.replace(/d/g, "o4f"));
trace(tweet.replace(/e/g, "o4g"));
trace(tweet.replace(/f/g, "o4a"));
trace(tweet.replace(/g/g, "o4b"));
trace(tweet.replace(/h/g, "o5c"));
trace(tweet.replace(/i/g, "o5d"));
trace(tweet.replace(/j/g, "o5e"));
trace(tweet.replace(/k/g, "o5f"));
trace(tweet.replace(/l/g, "o5g"));
trace(tweet.replace(/m/g, "o5a"));
trace(tweet.replace(/n/g, "o5b"));
trace(tweet.replace(/o/g, "o4c"));
trace(tweet.replace(/p/g, "o4d"));
trace(tweet.replace(/q/g, "o4e"));
trace(tweet.replace(/r/g, "o4f"));
trace(tweet.replace(/s/g, "o4g"));
trace(tweet.replace(/t/g, "o4a"));
trace(tweet.replace(/u/g, "o4b"));
trace(tweet.replace(/v/g, "o5c"));
trace(tweet.replace(/w/g, "o5d"));
trace(tweet.replace(/x/g, "o5e"));
trace(tweet.replace(/y/g, "o5f"));
trace(tweet.replace(/z/g, "o5g"));
trace(tweet.replace(/A/g, "CAPS_A"));
trace(tweet.replace(/B/g, "CAPS_B"));
trace(tweet.replace(/C/g, "CAPS_C"));
trace(tweet.replace(/D/g, "CAPS_D"));
trace(tweet.replace(/E/g, "CAPS_E"));
trace(tweet.replace(/F/g, "CAPS_F"));
trace(tweet.replace(/G/g, "CAPS_G"));
trace(tweet.replace(/H/g, "CAPS_H"));
trace(tweet.replace(/I/g, "CAPS_I"));
trace(tweet.replace(/J/g, "CAPS_J"));
trace(tweet.replace(/K/g, "CAPS_K"));
trace(tweet.replace(/L/g, "CAPS_L"));
trace(tweet.replace(/M/g, "CAPS_M"));
trace(tweet.replace(/N/g, "CAPS_N"));
trace(tweet.replace(/O/g, "CAPS_O"));
trace(tweet.replace(/P/g, "CAPS_P"));
trace(tweet.replace(/Q/g, "CAPS_Q"));
trace(tweet.replace(/R/g, "CAPS_R"));
trace(tweet.replace(/S/g, "CAPS_S"));
trace(tweet.replace(/T/g, "CAPS_T"));
trace(tweet.replace(/U/g, "CAPS_U"));
trace(tweet.replace(/V/g, "CAPS_V"));
trace(tweet.replace(/W/g, "CAPS_W"));
trace(tweet.replace(/X/g, "CAPS_X"));
trace(tweet.replace(/Y/g, "CAPS_Y"));
trace(tweet.replace(/Z/g, "CAPS_Z"));
trace(tweet.replace(/å/g, "o4c"));
trace(tweet.replace(/Å/g, "o4c2"));
trace(tweet.replace(/ä/g, "o4c"));
trace(tweet.replace(/Ä/g, "o4c2"));
trace(tweet.replace(/á/g, "o4c"));
trace(tweet.replace(/Á/g, "o4c2"));
trace(tweet.replace(/à/g, "o4c"));
trace(tweet.replace(/À/g, "o4c2"));
trace(tweet.replace(/é/g, "o4g"));
trace(tweet.replace(/É/g, "o4g2"));
trace(tweet.replace(/è/g, "o4g"));
trace(tweet.replace(/È/g, "o4g2"));
trace(tweet.replace(/ë/g, "o4g"));
trace(tweet.replace(/Ë/g, "o4g2"));
trace(tweet.replace(/ú/g, "o4b"));
trace(tweet.replace(/Ú/g, "o4b2"));
trace(tweet.replace(/ù/g, "o4b"));
trace(tweet.replace(/Ù/g, "o4b2"));
trace(tweet.replace(/ü/g, "o4b"));
trace(tweet.replace(/Ü/g, "o4b2"));
trace(tweet.replace(/í/g, "o5d"));
trace(tweet.replace(/Í/g, "o5d2"));
trace(tweet.replace(/ì/g, "o5d"));
trace(tweet.replace(/Ì/g, "o5d2"));
trace(tweet.replace(/ï/g, "o5d"));
trace(tweet.replace(/Ï/g, "o5d2"));
trace(tweet.replace(/ó/g, "o4c"));
trace(tweet.replace(/Ó/g, "o4c2"));
trace(tweet.replace(/ò/g, "o4c"));
trace(tweet.replace(/Ò/g, "o4c2"));
trace(tweet.replace(/ö/g, "o4c"));
trace(tweet.replace(/Ö/g, "o4c2"));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否完全理解您要做什么,但我确实知道 String.replace() 将返回一个包含替换内容的新字符串,并且不会触及您发送的字符串,因此您需要执行以下操作:
I'm not sure I understand exactly what you are trying to do, but I do know that String.replace() will return a new String with the replaced contents and not touch the one you sent in, so you will need to go: