我有一组像
data <- c("ABS Spring Meeting 5.14.15", "DEFG Sellors Tour 10.28.14", "DDCC Fun at the Museum 4.4.15", "GAME CS vs. Washington 11.01.14", "BSS Studio 54 5.13.15","Pas-12 3.5.15")
Run Code Online (Sandbox Code Playgroud)
您可以注意到,最后一组数字是事件日期.我想把它们转换成日期
date <- c("2015-05-14","2014-10-28","2015-04-04","2014-11-01","2015-05-13","2015-03-05")
Run Code Online (Sandbox Code Playgroud)
感觉我必须将这种类型("5.14.15","10.28.14","4.4.15","11.01.14","5.13.15","3.5.15")子串到子模式,然后做转换日期.
谁能帮我这个?谢谢!
我想从像这样的文件字符串中删除路径:
Root\ToOrganization\Service_b37189b3-8505-4395_Out_BackOffice.xml
Run Code Online (Sandbox Code Playgroud)
我试图找到最后一次出现的"\"的索引,所以我可以使用子串到那里.
但我不能在搜索中使用字符"\".我正在使用"\",但它不起作用......
我正在尝试的代码:
$file = "Root\ToOrganization\Service_b37189b3-8505-4395_Out_BackOffice.xml";
$tmp = rindex($file, "\\");
print $tmp;
Run Code Online (Sandbox Code Playgroud)
我得到的输出:
-1
Run Code Online (Sandbox Code Playgroud)
我能做什么?
我正在尝试制作一个计算器应用程序,我输入的最终方程有一个字符串."983 + 388 + 12"我的解决方法是首先确定运营商的位置.在此之后,我向后和向前循环尝试找到2个数字,然后我添加它们.所以我会找到加号然后是983和388并添加它们.我在匹配与添加符号相关的上一个/下一个数字时遇到问题.
public static void main(String[] args)
{
int plus=0;
String string="983+388+12";
//locating Plus symbol
for(int i=0;i<string.length();i++)
{
if(string.charAt(i)=='+')
{
plus=i;
}
}
//locating next number (should be 388)
for(int i=plus+1;i<string.length();i++)
{
if(string.charAt(i)=='+' || string.charAt(i)=='-')
{
String nextNumber=string.substring(plus+1, i-1);
System.out.println(nextNumber);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我没有得到任何返回作为nextNumber的值
我有长度大于150个字符的字符串.我想删除前17个字符,剩下的就剩下了.我在ASP.net 4.5中使用Substring方法但是我在str0收到错误消息:"System.ArgumentOutOfRangeException".
public static string extract(string dirinfo)
{
Int32 lensub = Convert.ToInt32(dirinfo.Length);
string str0 = dirinfo.Substring(17, lensub);
return str0;
}
Run Code Online (Sandbox Code Playgroud) 我试图在第三个斜杠后获取字符串.但我不知道该怎么做.我曾经使用过分裂,但这不是我想要的.
for(String obj2: listKey.getCommonPrefixes()){
Map<String, String> map = new HashMap<String, String>();
String[] id = obj2.split("/");
if (id.length > 3) {
String name = id[3];
map.put("id", name);
map.put("date", "null");
map.put("size", String.valueOf(obj2.length()));
keys.add(map);
}
}
Run Code Online (Sandbox Code Playgroud)
id[3]只给了我id[3]但是我想要在第三次斜线之后的所有东西?我怎样才能做到这一点?
我有一个字符串日期,我想分成整数:年,月和日.例如,20160622应该返回year = 2016,month = 06和day = 22.这是代码:
String dateString = "20160622";
int year = Int32.Parse(dateString.Substring(0, 4));
Console.WriteLine("year is " +year);
Console.ReadKey();
int month = Int32.Parse(dateString.Substring(4, 2));
Console.WriteLine("month is " + month);
Console.ReadKey();
int jour = Int32.Parse(dateString.Substring(6, 2));
Console.WriteLine("day is " + jour);
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
当子串的第一个字符为'0'时,它不会作为子字符串的一部分返回.我得到以下输出:
year is 2016
month is 6
day is 22
Run Code Online (Sandbox Code Playgroud)
但我想得到
year is 2016
month is 06
day is 22
Run Code Online (Sandbox Code Playgroud) 我有一个字符串,North Ridge NJ 01234我想将它们拆分为City,State和zip以存储到数据库中.我试图基于空格分割,我得到四个子串而不是三个.有什么办法我可以向后拆分但只能在两个空间上拆分吗?
我有一个如下的列数据,
126-35-56-24
Run Code Online (Sandbox Code Playgroud)
我希望结果像,
select 126 as Id, 35 as Age, 56 as EmpId, 24 as Day
Run Code Online (Sandbox Code Playgroud)
我只是尝试使用substring,我可以将字符串分成126和35-56-24,但我无法得到我想要的结果.
请帮我搞定.提前致谢...
我正在用awk编写一个脚本,用文件夹中所有文件的双重双引号替换所有双引号.
我在stackoverflow中发现了这个,但我得到了其他结果
awk 'BEGIN{FS=OFS="#"} {for (i=0;i<=NF;i++) gsub(/"/, "&&",$i)} 1 $f3 > $f2
Run Code Online (Sandbox Code Playgroud)
此示例示例的输出:
01##"hello world"98##
Run Code Online (Sandbox Code Playgroud)
是
01##""""hello world""""98##
Run Code Online (Sandbox Code Playgroud)
我想得到
01##""hello world""98##
Run Code Online (Sandbox Code Playgroud) 根据我的理解,JavaScript的substring方法有两个参数:第一个是从哪里开始的索引,第二个是结束点(非索引类型计数,也就是字符数不是0-开始),不包括结尾点char.遵循这个逻辑,我运行了两个例子:
第一个例子如预期的那样工作,我计算了13个字符,因为第13个字符是终点并且不会被包括在内.
// goal was to print "Melbourne is"
alert("Melbourne is great".substring(0,13));
Run Code Online (Sandbox Code Playgroud)
然而这个例子失败了.在这个例子中,我也在结束点停止了我的计数,因为我预计它不会被计算在内.
//goal was to print "Jan"
alert("January".substring(0,4));
Run Code Online (Sandbox Code Playgroud)
我的理解在哪里有缺陷?