我想用白色空格分割一个字符串,除非字符串中的文本是双引号("text")或单引号('text').
我正在使用此功能:
public static string[] ParseKeywordExpression(string keywordExpressionValue, bool isUniqueKeywordReq)
{
keywordExpressionValue = keywordExpressionValue.Trim();
if (keywordExpressionValue == null || !(keywordExpressionValue.Length > 0))
return new string[0];
int idx = keywordExpressionValue.Trim().IndexOf(" ");
if (idx == -1)
return new string[] { keywordExpressionValue };
//idx = idx + 1;
int count = keywordExpressionValue.Length;
ArrayList extractedList = new ArrayList();
while (count > 0)
{
if (keywordExpressionValue[0] == '"')
{
int temp = keywordExpressionValue.IndexOf(BACKSLASH, 1, keywordExpressionValue.Length - 1);
while (keywordExpressionValue[temp - 1] == …Run Code Online (Sandbox Code Playgroud) 我在遇到以下问题时遇到了很多麻烦,似乎无法通过广泛的搜索找到答案.如果我有以下内容:
> fac1 <- factor(c("a", "b", "c"))
> fac2 <- factor(c("d", "e", "f"))
> fac3 <- interaction(fac1,fac2)
> fac3
[1] a.d b.e c.f
Levels: a.d b.d c.d a.e b.e c.e a.f b.f c.f
Run Code Online (Sandbox Code Playgroud)
我可以运行什么功能来拆分fac3,以便获得投入交互的原始因素的级别?以便:
> myFun(fac3, 1)
[1] "a" "b" "c" "a" "b" "c" "a" "b" "c"
> myFun(fac3, 2)
[2] "d" "d" "d" "e" "e" "e" "f" "f" "f"
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用String.split()将一些字符串划分为IP但是它returning an empty array,所以我使用String.substring()解决了我的问题,但我想知道为什么不按预期工作,我的代码是:
// filtrarIPs("196.168.0.1 127.0.0.1 255.23.44.1 100.168.100.1 90.168.0.1","168");
public static String filtrarIPs(String ips, String filtro) {
String resultado = "";
String[] lista = ips.split(" ");
for (int c = 0; c < lista.length; c++) {
String[] ipCorta = lista[c].split("."); // Returns an empty array
if (ipCorta[1].compareTo(filtro) == 0) {
resultado += lista[c] + " ";
}
}
return resultado.trim();
}
Run Code Online (Sandbox Code Playgroud)
它应该返回String[] as {"196"."168"."0"."1"}....
我正在尝试用regexp_subtr拆分字符串,但我无法使它工作.
所以,首先,我有这个查询
select regexp_substr('Helloworld - test!' ,'[[:space:]]-[[:space:]]') from dual
Run Code Online (Sandbox Code Playgroud)
非常好地提取我的分隔符 - 空白 - 空白
但是,当我尝试使用此选项拆分字符串时,它只是不起作用.
select regexp_substr('Helloworld - test!' ,'[^[[:space:]]-[[:space:]]]+')from dual
Run Code Online (Sandbox Code Playgroud)
查询什么都不返回.
将非常感谢帮助!谢谢
所以这是字符串s:
"Hi! How are you? I'm fine. It is 6 p.m. Thank you! That's it."
Run Code Online (Sandbox Code Playgroud)
我希望它们被分隔为一个数组:
["Hi", "How are you", "I'm fine", "It is 6 p.m", "Thank you", "That's it"]
Run Code Online (Sandbox Code Playgroud)
这意味着分隔符应为". "+ "? "+"! "
我试过了:
let charSet = NSCharacterSet(charactersInString: ".?!")
let array = s.componentsSeparatedByCharactersInSet(charSet)
Run Code Online (Sandbox Code Playgroud)
但它也将分为p.m.两个元素.结果:
["Hi", " How are you", " I'm fine", " It is 6 p", "m", " Thank you", " That's it"]
Run Code Online (Sandbox Code Playgroud)
我也试过了
let array = s.componentsSeparatedByString(". ") …Run Code Online (Sandbox Code Playgroud) 是否有可能不仅拆分一个字符串而且拆分一串字符串?即
strings.Split("Dogs and Cats are Great", "and"))
Run Code Online (Sandbox Code Playgroud)
但不是使用一个字符串,而是使用一段字符串:
strings.Split("Dogs and Cats are Great", []string{"and", "are"}))
Run Code Online (Sandbox Code Playgroud) I have a string which its first part is a string and last one is a number, like this:
ahde7394
so what I would like to obtain is:
ahde
7394
I have thought to first extract the string and then from the last position of the character obtain the number until the end of the string so I think using indexers can be done somehow:
var stringQuery = NameComp.Select((str,index) => new {myStr=str, position=index})
.Where(c => !Char.IsDigit(c.myStr)).Select((ch,pos) => new { newStr=ch, …Run Code Online (Sandbox Code Playgroud) 我想将PHP中的字符串拆分为"名称"部分(字符串)和"键"部分(整数数组).
输入示例:
$input = "Sum(1, 5, 7)";
Run Code Online (Sandbox Code Playgroud)
期望的输出:
$name = "Sum";
$keys = [1, 5, 7];
Run Code Online (Sandbox Code Playgroud)
我一直在看爆炸,str_split preg_split,我确信有很多可能的实现.什么是最优雅的解决方案?
我有这样的字符串:str:='ac_Abc.88,ac_Abc.99,ac_Abc.77'.我需要在用逗号(,)分割后得到第一个元素.所以即时使用像这样:
str VARCHAR2(500);
dbms_utility.comma_to_table
( list => regexp_replace(str,'(^|,)','\1')
, tablen => l_count
, tab => l_array
);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ORA-20001: comma-separated list invalid near bc.88
ORA-06512: at "SYS.DBMS_UTILITY", line 239
ORA-06512: at "SYS.DBMS_UTILITY", line 272
Run Code Online (Sandbox Code Playgroud)
但如果我有这样的字符串,str:='ac_Abc88,ac_Abc99,ac_Abc77',同样的方法工作正常并给我预期的结果.
所以我想有些东西需要纠正才能考虑"." 作为常规角色.你能建议我怎么解决这个问题.
我试图拆分下面的字符串,但我想排除其中的所有内容[[......]].我已尝试使用我在此处找到的多个建议,但它们都没有工作.
[675: test, 676: test1, 677: test2, 678: [[{"id":0,"value":"15"},{"id":1,"value":"2"},
{"id":2,"value":"2"}],[{"id":0,"value":"2"},{"id":1,"value":"3"},
{"id":2,"value":"3"}],[{"id":0,"value":"5"},{"id":1,"value":"6"},
{"id":2,"value":"6"}],[{"id":0,"value":"7"},{"id":1,"value":"8"}],
[{"id":0,"value":"99"},{"id":1,"value":"8"},{"id":2,"value":"7"}]]]
Run Code Online (Sandbox Code Playgroud)
我希望能够得到这样的结果:
675: test
676: test1
677: test2
678: [[{"id":0,"value":"15"},{"id":1,"value":"2"}, {"id":2,"value":"2"}],
[{"id":0,"value":"2"},{"id":1,"value":"3"},{"id":2,"value":"3"}],
[{"id":0,"value":"5"},{"id":1,"value":"6"}, {"id":2,"value":"6"}],
[{"id":0,"value":"7"},{"id":1,"value":"8"}],
[{"id":0,"value":"99"},{"id":1,"value":"8"},{"id":2,"value":"7"}]]]
Run Code Online (Sandbox Code Playgroud)
我尝试用逗号分割字符串,但也拆分了方括号中包含的所有数据.
谢谢