Решение с использованием stringr
library(data.table)
library(stringr)
library(dplyr)
dataDT <- data.table(data = c("1,10,some text... , some text,,20190801",
"2,22,some text... , some text,,20190801",
"3,30,some text... , some text,,20170601"))
dataDT <- dataDT %>%
mutate(
ColA = str_extract(data, "^[^,]*(?=,)"),
ColB = str_extract(data, "(?<=,)[^,]*(?=,)"),
ColD = str_extract(data, "(?<=,)[^,]*$"),
ColC = str_sub(data, nchar(ColA)+nchar(ColB)+3, nchar(data)-nchar(ColD)-1)
) %>%
select(ColA, ColB, ColC, ColD)
dataDT
#> ColA ColB ColC ColD
#> 1 1 10 some text... , some text, 20190801
#> 2 2 22 some text... , some text, 20190801
#> 3 3 30 some text... , some text, 20170601
Создано в 2019-06-27 с помощью пакета представитель (v0.3.0) sup>
Это невозможно сделать напрямую в JavaScript. Вам нужно будет встроить короткий WAV-файл в HTML, а затем воспроизвести его с помощью кода.
Пример:
<script>
function PlaySound(soundObj) {
var sound = document.getElementById(soundObj);
sound.Play();
}
</script>
<embed src="success.wav" autostart="false" width="0" height="0" id="sound1"
enablejavascript="true">
Затем вы могли бы вызвать его из кода JavaScript как таковой:
PlaySound("sound1");
Это должно делать именно то, что вы хотите - вам просто нужно самостоятельно найти / создать звуковой сигнал, что должно быть тривиально.
Вам нужен звуковой файл, который будет откуда-то обслуживаться. Вот код из звуковой библиотеки Scriptaculous :
//Default:
<embed style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>
//For Gecko:
if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
Sound.template = new Template('<object id="sound_#{track}_#{id}" type="application/x-mplayer2" data="#{url}"></object>');
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
Sound.template = new Template('<embed type="audio/x-pn-realaudio-plugin" style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>');
else
Sound.play = function(){};
}
Нет кроссбраузерного способа добиться этого с помощью чистого javascript. Вместо этого вы можете использовать небольшой файл .wav, который вы воспроизводите, используя теги embed или object.