好的,所以我有这个 AutoHotkey 片段:
; Google text from any app
; from http://superuser.com/questions/7271/most-useful-autohotkey-scripts/165220#165220
#s::
MyClip := ClipboardAll
clipboard = ; empty the clipboard
Send, ^c
ClipWait, 2
if ErrorLevel ; ClipWait timed out.
return
Run http://www.google.com/#hl=en&q=%clipboard%
Clipboard := MyClip
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想改进它以处理您突出显示 URL 并自动运行 URL 本身 ( Run %clipboard%) 而不是 Google 搜索的情况。如何让 AutoHotkey 检测字符串是否为 URL?
似乎我可以使用StringLeftorSubStr提取前几个字符并查看它们是否匹配http://or www.,或者使用正则表达式可能更强大?不过,我不太了解 AHK 的语法。
此脚本检查剪贴板中的 URL,显然使用StringGetPos,但我不想检测 www 是否出现在字符串中的任何位置。仅当它出现在开头时。
这是我正在尝试做的事情,但失败了:
我试图从长度超过 12000 个字符的列中检索地址。幸运的是,我可以通过 XML 标签找到地址 line1:
<PermanentAddress> <AddressLine><![CDATA[1234 1st street]]></AddressLine> <City>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的:
select
substring(PC.css_record, CHARINDEX('<AddressLine>', PC.css_record)+ 21, CHARINDEX('</AddressLine>', PC.css_record))
from
table1
Run Code Online (Sandbox Code Playgroud)
我也尝试在那里压缩长度函数来计算我的子字符串函数的长度结束,但这只是给了我一个错误(可能是因为我是 SQL 新手并且仍在学习和使用它错误)。
另外,有多个标签,但我只关心第一个。
如果有人可以帮助我,那将是非常棒的!
谢谢!
这与在字符串中查找子字符串的所有位置略有不同,因为我希望它可以处理后跟空格、逗号、分号、冒号、句号、感叹号和其他标点符号的单词。
我有以下函数来查找子字符串的所有位置:
function strallpos($haystack,$needle,$offset = 0){
$result = array();
for($i = $offset; $i<strlen($haystack); $i++){
$pos = strpos($haystack,$needle,$i);
if($pos !== FALSE){
$offset = $pos;
if($offset >= $i){
$i = $offset;
$result[] = $offset;
}
}
}
return $result;
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我尝试查找子字符串“us”的所有位置,它将返回“prospectus”或“inclusive”等中出现的位置。
有什么办法可以防止这种情况吗?可能使用正则表达式?
谢谢。斯特凡
这个问题与这里的一个现有主题有关..
但是如果我想从字符串的特定索引中删除特定数量的字符怎么办?
例如
(i want to remove 8 characters from the fourth index)
$input = 'asdqwe123jklzxc';
$output = 'asdlzxc';
Run Code Online (Sandbox Code Playgroud) 我浏览了String和StringBufferAPI,当您调用该substring方法时,两者在内部的工作方式似乎相同。两者都有对原始字符数组 ( char[] original)的引用,因此两者都使用相同的空间。那为什么是StringBuffer首选呢?那么 stringbuffer.substring(2,4) 与 string.substring(2,4) 有何不同。
StringBuffer 的子串方法:
public String substring(int start, int end) {
return new String(value, start, end - start);
}
Run Code Online (Sandbox Code Playgroud)
字符串的子串方法:
public String substring(int beginIndex, int endIndex) {
return ((beginIndex == 0) && (endIndex == value.length)) ? this
: new String(value, beginIndex, subLen);
}
Run Code Online (Sandbox Code Playgroud)
两个子字符串变体然后调用 String 构造函数:
public String(char value[], int offset, int count) {
this.value = Arrays.copyOfRange(value, offset, offset+count);
}
Run Code Online (Sandbox Code Playgroud)
它调用以下 Arrays 类的方法:
public static …Run Code Online (Sandbox Code Playgroud) 我有一张person桌子name列包含名称,一些格式为“first last”,一些格式为“first”。
我的查询
SELECT name,
SUBSTRING(name FROM 1 FOR POSITION(' ' IN name) ) AS first_name
FROM person
Run Code Online (Sandbox Code Playgroud)
创建一行新的名字,但它不适用于只有名字而根本没有空格的名字。
我知道我需要一个CASE类似的语句,0 = (' ', name)但我一直遇到语法错误,希望得到一些指导。
我知道 KMP 算法依赖于有类似于后缀的前缀的辅助数组。当上述条件不满足时,它不会有效,因为在辅助数组中包含全零。运行时间是 O(m + n) 吗?如果我是对的,在这种情况下什么是更好的子串算法?
我string喜欢这个http://domain.sf/app_local.php/foo/bar/33.最后的字符是id元素.他的长度不止一个,所以我不能用:
substr($dynamicstring, -1);
Run Code Online (Sandbox Code Playgroud)
在这种情况下必须
substr($dynamicstring, -2);
Run Code Online (Sandbox Code Playgroud)
如何在"/ bar /"之后获取caracters string而不取决于长度?
我需要知道 R 中是否有任何可用的函数可以让我检查一个字符串是否包含子字符串并返回一个布尔值。我已经试过了,str_detect但这不适合我的需要。
例如:
string = 12345REFUND4567
Run Code Online (Sandbox Code Playgroud)
和
substring = REFUND
Run Code Online (Sandbox Code Playgroud)
contains(string,substring)理想情况下会返回,TRUE
因为12345REFUND4567contains REFUND。
contains(string,substring) 只是我想象的功能的格式。
我使用 MYSQL,而不是 SQL 我有这个表,我想选择没有“M”的表 这是我创建的表
CREATE TABLE test (
id VARCHAR(10)
);
INSERT INTO test (id) VALUES ('M1');
INSERT INTO test (id) VALUES ('M2');
....
INSERT INTO test (id) VALUES ('M128');
INSERT INTO test (id) VALUES ('M129');
Run Code Online (Sandbox Code Playgroud)
我希望代码选择是这样的:
Select Substring(id,1) from test
Run Code Online (Sandbox Code Playgroud)
结果是从“M1”->“M129”但是当代码是这样的:
Select Substring(id,2) from test
Run Code Online (Sandbox Code Playgroud)
结果是从 1 -> 129 所以起点是 1,而不是 0
但是当我在 W3school 或一些网站上阅读时,它说起点是
0。Somone 能告诉我为什么吗?
substring ×10
php ×3
sql ×3
string ×3
algorithm ×1
arrays ×1
autohotkey ×1
big-o ×1
delimiter ×1
java ×1
mysql ×1
postgresql ×1
r ×1
regex ×1
sql-server ×1
stringbuffer ×1
url ×1
words ×1