如何从VBA字符串数组中提取第n个元素?
我有一个字符串,如: TEST - 2017/01/20 = Invoice
我希望尽可能简洁地提取出第二和第三个元素.我正在尝试像这样的Javascripty,这不起作用,所以必须有一个VBA方式:
Dim Report As String
Dim CurrLine As String
Dim CurrDate As String
Dim CurrTask As String
CurrLine = "TEST - 2017/01/20 = Invoice"
CurrDate = Trim(Split(CurrLine, '-')[1])
CurrTask = Trim(Split(CurrLine, '=')[1])
Report = Report & CHR(34) & CurrDate & CHR(34) & "," & CHR(34) & CurrTask & CHR(34)
//result: "2017/01/20","Invoice"
Run Code Online (Sandbox Code Playgroud) 使用 TamperMonkey 简化我这边的页面视图,并希望隐藏部分外部来源的 Twitter 卡片以防止打印。EmbeddedTweet 中的图像无论如何都不会打印,并留下一个大的空白矩形,浪费了宝贵的空间。
DOM 如下图所示 - 我将如何使用类SummaryCard-image
(绿色箭头)定位 DIV ?对我来说,DIV 是从 DOM 中删除还是用 CSS 隐藏都无关紧要。
我尝试了以下方法,但都不起作用:
(1) 注入 CSS .SummaryCard-image{display:none !important;}
(2) jQuery: $('.SummaryCard-image').remove();
$('.SummaryCard-image').length
返回 0
(注意
#shadow-root (open)
从顶部开始的第二个元素)
我有一个包含数百个对象的数组,每个对象都有一个类别。我希望返回一个对象,该对象列出了类别以及每个类别的项目数。
const arr = [
{id: 1, name: 'ford', category: 'vehicle'},
{id: 2, name: 'pig', category: 'animal'},
{id: 3, name: 'dog', category: 'animal'},
{id: 4, name: 'chev', category: 'vehicle'},
{id: 5, name: 'cat', category: 'animal'},
{id: 6, name: 'jeep', category: 'vehicle'},
{id: 7, name: 'honda', category: 'vehicle'}
]
Run Code Online (Sandbox Code Playgroud)
我如何循环遍历该对象并创建一个仅包含两个类别以及每个类别有多少个的新对象?
期望的输出:
{vehicle: 4, animal: 3}
Run Code Online (Sandbox Code Playgroud)
代码:
const arr = [
{id: 1, name: 'ford', category: 'vehicle'},
{id: 2, name: 'pig', category: 'animal'},
{id: 3, name: 'dog', category: 'animal'},
{id: 4, name: …
Run Code Online (Sandbox Code Playgroud)在 VSCode 中,尝试搜索print(
和print (
- 但前提是后面没有#
这是我第一次尝试在 VSCode 中进行正则表达式搜索...
示例:
print ('Test One')
- 匹配
print( 'Test Two')
- 匹配
#print('Test Fee')
- 跳过
我从这个问题中了解到 VSCode 缺乏负面回顾。
通常,在^F
(搜索功能)中,我会使用类似(未经测试)的内容:
/w*(?<!#)print
Run Code Online (Sandbox Code Playgroud)
但我收到正则表达式无效的错误。
任何人都可以提出解决方法 - 或者我只是对正则表达式进行了胖手指?
PHP通过JSON格式的AJAX接收它(让我们称之为$json_string
):
[{"pid":"284","qty":"1","sn":"12"},{"pid":"284","qty":"1","sn":"23"},{"pid":"276","qty":"1","sn":"34"},{"pid":"276","qty":"1","sn":"45"},{"pid":"276","qty":"1","sn":"56"},{"pid":"281","qty":"1","sn":"57"},{"pid":"281","qty":"1","sn":"67"},{"pid":"281","qty":"1","sn":"78"}]
我希望循环遍历数组,如下所示:
$out = '<table>';
$arr = json_decode($json_string);
foreach ($arr AS $row){
$out .= '<tr><td>'.$row['pid'].'</td><td>'.$row['qty'].'</td><td>'.$row['sn'].'</td></tr>';
}
$out .= '</table>';
Run Code Online (Sandbox Code Playgroud)
我收到一个错误: Fatal error: Cannot use object of type stdClass as array
你如何在 React 的quill.js中关闭拼写检查?
我发现这个 GitHub 页面显示了如何在普通 JavaScript 中禁用 quill 的拼写检查器:
const quill = new Quill('#editor-container')
quill.root.setAttribute('spellcheck', false)
Run Code Online (Sandbox Code Playgroud)
但是,我看不到如何使用 React 组件来实现这一点。
我的 React 组件(实际上是 Preact):
const quill = new Quill('#editor-container')
quill.root.setAttribute('spellcheck', false)
Run Code Online (Sandbox Code Playgroud)
这可能很明显,但为什么在为这个javascript数组添加键值对时,我没有得到预期的JSON字符串?
下一步:当代码显示时,我实际上希望在对象中有两个数据集.
jsFiddle here - 很奇怪,目前只在Chrome中"有效"
var myKey = "123", myVal="Car";
var arrSummat = new Array();
$('#mybutt').click(function(){
arrSummat["987"] = "Boat";
//arrSummat[myKey] = myVal;
var test = JSON.stringify(arrSummat);
alert(test);
});
Run Code Online (Sandbox Code Playgroud) 通过集合循环<li>
元件以去除一个特定的类,前重新添加同一类到不同的<li>
。这是代码:
useEffect(() => {
if (dnArrowIdx === undefined) {
const allLi = Array.from(document.querySelectorAll('#srxResultsDiv ul li'));
const dLi = document.querySelector(`#srxResultsDiv ul li:nth-child(${dnArrowIdx})`);
if (allLi !== null) {
allLi.forEach((li) => {
li.removeClass('liHoverBg');
});
}
if (dLi !== null) dLi.classList.add('liHoverBg');
}
}, [dnArrowIdx]);
Run Code Online (Sandbox Code Playgroud)
该removeClass
线li.removeClass('liHoverBg')
是红色下划线。错误信息是:
Property 'removeClass' does not exist on type 'Element'.ts(2339)
Run Code Online (Sandbox Code Playgroud)
我将如何解决这个问题?
我仍然在努力处理函数,变量和范围.
我读过几篇文章"解释"这些概念,加上一些看似相关的帖子,但无法想出这一点.有人能告诉我如何访问函数外的vars ip/prov/country
这里是工作的代码(乏访问内部的FN):
$.get("http://ipinfo.io", function (response) {
var ip, prov, country;
ip = response.ip;
prov = response.region;
country = response.country;
alert( 'IP: '+ip+ ' ** Prov: ' +prov+ ' ** Country: ' +country );
}, "jsonp");
Run Code Online (Sandbox Code Playgroud)
但是,我想访问函数外部的变量,以便稍后使用.
这在我的网站上不起作用(所有项目显示为"未定义"):
var ip, prov, country;
$.get("http://ipinfo.io", function (response) {
ip = response.ip;
prov = response.region;
country = response.country;
}, "jsonp");
alert( 'IP: '+ip+ ' ** Prov: ' +prov+ ' ** Country: ' +country );
Run Code Online (Sandbox Code Playgroud)
但是,它在这个jsFiddle中工作得很好!
此外,这不起作用(所有未定义):
var ip, …
Run Code Online (Sandbox Code Playgroud) 我试图在javascript中转置一个对象数组.
我有这个对象数组:
var myData = [
{"shift":"1","date":"01/01/2016/08/00/00","car":"178","truck":"255","bike":"317","moto":"237"},
{"shift":"2","date":"01/01/2016/17/00/00","car":"125","truck":"189","bike":"445","moto":"273"},
{"shift":"3","date":"02/01/2016/08/00/00","car":"140","truck":"219","bike":"328","moto":"412"},
{"shift":"4","date":"02/01/2016/17/00/00","car":"222","truck":"290","bike":"432","moto":"378"},
{"shift":"5","date":"03/01/2016/08/00/00","car":"200","truck":"250","bike":"420","moto":"319"},
{"shift":"6","date":"03/01/2016/17/00/00","car":"230","truck":"220","bike":"310","moto":"413"},
{"shift":"7","date":"04/01/2016/08/00/00","car":"155","truck":"177","bike":"377","moto":"180"},
{"shift":"8","date":"04/01/2016/17/00/00","car":"179","truck":"203","bike":"405","moto":"222"},
{"shift":"9","date":"05/01/2016/08/00/00","car":"208","truck":"185","bike":"360","moto":"195"},
{"shift":"10","date":"05/01/2016/17/00/00","car":"150","truck":"290","bike":"315","moto":"280"},
{"shift":"11","date":"06/01/2016/08/00/00","car":"200","truck":"220","bike":"350","moto":"205"},
{"shift":"12","date":"06/01/2016/17/00/00","car":"230","truck":"170","bike":"390","moto":"400"}
];
out = '';
$.each(myData, function(ndx,obj){
out += '{';
$.each(obj, function(key,val){
out += key +':'+ val +',';
});
out += '}<br>';
});
$('body').append(out);
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我需要它进行转置,以便(转置时)它看起来像这样(注意:我手动完成,我需要以编程方式进行 - 并按上面的方式打印):
var myData2 = [
{"shift":"1","shift":"2","shift":"3","shift":"4","shift":"5","shift":"6","shift":"7","shift":"8","shift":"9","shift":"10","shift":"11","shift":"12"},
{"date":"01/01/2016/08/00/00","date":"01/01/2016/17/00/00","date":"02/01/2016/08/00/00","date":"02/01/2016/17/00/00","date":"03/01/2016/08/00/00","date":"03/01/2016/17/00/00","date":"04/01/2016/08/00/00","date":"04/01/2016/17/00/00","date":"05/01/2016/08/00/00","date":"05/01/2016/17/00/00","date":"06/01/2016/08/00/00","date":"06/01/2016/17/00/00"},
{"car":"178","car":"125","car":"140","car":"222","car":"200","car":"230","car":"155","car":"179","car":"208","car":"150","car":"200","car":"230"},
{"truck":"255","truck":"189","truck":"219","truck":"290","truck":"250","truck":"220","truck":"177","truck":"203","truck":"185","truck":"290","truck":"220","truck":"170"},
{"bike":"317","bike":"445","bike":"328","bike":"432","bike":"420","bike":"310","bike":"377","bike":"405","bike":"360","bike":"315","bike":"350","bike":"390"},
{"moto":"237","moto":"273","moto":"412","moto":"378","moto":"319","moto":"413","moto":"180","moto":"222","moto":"195","moto":"280","moto":"205","moto":"400"}
];
Run Code Online (Sandbox Code Playgroud)
javascript ×7
arrays ×3
jquery ×3
reactjs ×2
excel ×1
excel-vba ×1
json ×1
php ×1
preact ×1
quill ×1
regex ×1
shadow-dom ×1
tampermonkey ×1
typescript ×1
vba ×1