标签: string-parsing

从字符串中提取日期值

论坛。

我的代码从 Excel 文件读取并在变量“textContainingDate”中获取以下字符串:

"Employee Filter: All Employees; Time Entry Dates: 01/07/2016-01/07/2016; Exceptions: All Exceptions"
Run Code Online (Sandbox Code Playgroud)

我想做的是从字符串中提取日期值。尽管有两个日期被读取为日期范围,但这两个日期将始终相同。我的想法是,无论情况如何,我都会对第一次约会感到满意。

var dateTime = DateTime.ParseExact(textContainingDate, "MM/dd/yyyy", CultureInfo.CurrentCulture);
Run Code Online (Sandbox Code Playgroud)

我尝试使用上述声明,该声明是我从其他 stackoverflow 问题和 Google 搜索文章中拼凑而成的。根据我所读到的内容,我相信它失败了,因为它只需要一个日期字符串。

任何有关解决方案和/或阅读哪些文本以找到解决方案的方向的建议都将受到赞赏。

c# parsing date string-parsing

3
推荐指数
1
解决办法
1万
查看次数

将用户 arg 传递给 DESeq2 函数

DESeq我正在尝试使用从命令行输入的参数在 RScript 中运行。我曾经optparse解析用户参数并尝试将设计参数传递到函数中DESeqDataSetFromMatrix()

我直接测试了这个功能,效果很好:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=~taxonomy)
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试传递变量opt$design(这是一个字符串=“~taxonomy”),我会收到以下错误:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=opt$design)
Run Code Online (Sandbox Code Playgroud)

错误:$ 运算符对于原子向量无效执行停止

我尝试过/noquote()的各种组合并将整个命令创建为字符串以传递给函数,但没有任何效果。任何建议将不胜感激。catpasteDESeqDataSetFromMatrix()

解决方案

感谢 Ben Bolker 下面的回答,以下方法有效:

DESeq_tbl <- DESeqDataSetFromMatrix(countData=counts_tbl,
colData=coldata, design=as.formula(opt$design))
Run Code Online (Sandbox Code Playgroud)

arguments r optparse string-parsing bioconductor

3
推荐指数
1
解决办法
348
查看次数

如何从这个字符串中获取日期?

我有这个字符串:

\tid <01CA4692.A44F1F3E@blah.blah.co.uk>; <b>Tue, 6 Oct 2009 15:38:16</b> +0100
Run Code Online (Sandbox Code Playgroud)

我希望将日期(大胆)提取到更有用的格式,例如06-10-2009 15:38:16

最好的方法是什么?

.net c# regex string-parsing

2
推荐指数
1
解决办法
9995
查看次数

如何从'MySQL Create Table'查询字符串中获取列名?

我想在PHP中编写一个脚本,将"MySQL Create Table"查询作为字符串并将列名称及其数据类型存储在数组中.

例如:

输入字符串:

CREATE TABLE `test` (
`col1` INT( 10 ) NOT NULL ,
`col2` VARCHAR( 50 ) NOT NULL ,
`col3` DATE NOT NULL
) ENGINE = MYISAM ;
Run Code Online (Sandbox Code Playgroud)

输出:

array(
    array( 'name'=>'col1', 'type'=>'INT', 'size'=>'10' ),
    array( 'name'=>'col2', 'type'=>'VARCHAR', 'size'=>'50' ),
    array( 'name'=>'col3', 'type'=>'DATE', 'size'=>'' )
);
Run Code Online (Sandbox Code Playgroud)

我没有数据库访问权来直接执行查询.有没有这个或任何想法的PHP库?

谢谢

php mysql string-parsing

2
推荐指数
1
解决办法
2257
查看次数

Javascript - 值存在,然后消失,然后再次出现?

这让我疯了.我也无法通过Firebug来解决这个问题.有人可以解释一下这里发生了什么吗?

基本上我有一个传入的文本文件,其中每行包含一个管道分隔的记录.我将这些字符串拆分为一个字符串数组,以便以后在自动完成文本框中使用.代码如下:

<script type="text/javascript">
$(function () {

    var rawData = new Array();
    $.get("/sample.txt",
        function (data) {
            var raw = data.split('\n');
            for (var i = 0; i < raw.length; i++) {
                rawData.push(raw[i].split('|'));
            };
            alert(rawData); // 1st sanity check
        }
    );
    alert(rawData); // 2nd sanity check
    alert(rawData); // 3rd sanity check
Run Code Online (Sandbox Code Playgroud)

由于某种原因,第一次完整性检查工作正常 - 它显示我所期望的所有数据.第二个显示rawData为空...但第三个显示所有数据.删除第1次完整性检查不会影响第2次和第3次.

这怎么可能?为什么会这样?这真让我抓狂.

javascript jquery scope multidimensional-array string-parsing

2
推荐指数
1
解决办法
681
查看次数

使用提升精神将字符串解析为struct

我有以下代码我需要解析一个字符串并将其移动到如下定义的结构:

#include "boost\spirit\include\classic.hpp"
#include "boost\spirit\include\qi.hpp"
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <regex>
#include <string>
#include <boost\chrono.hpp>
#include <ctype.h>
#include <iostream>

struct my_struct
{
   std::string s1;
   std::string s2;
   std::string s3;
   std::string s4;
   std::string s5;
   std::string s6;
   std::string s7;
   std::string s8;
   std::string s9;
   std::string s10;
   std::string s11;
};

BOOST_FUSION_ADAPT_STRUCT(
    my_struct,
    (std::string, s1 )
    (std::string, s2 )
    (std::string, s3 )
    (std::string, s4 )
    (std::string, s5 )
    (std::string, s6 )
    (std::string, …
Run Code Online (Sandbox Code Playgroud)

boost boost-spirit boost-fusion string-parsing boost-spirit-qi

2
推荐指数
1
解决办法
681
查看次数

bash:`read`似乎不尊重IFS

我的印象是设置IFS会改变read在将一行文本分成字段时使用的分隔符,但显然我遗漏了一些内容:

# OK: 'read' sees 3 items separated by spaces
$ (IFS=' '; x="aa bb cc"; echo "'$x'"; read a b c <<< $x;\
  echo "'$a' '$b' '$c'")
'aa bb cc'
'aa' 'bb' 'cc'

# OK: 'read' sees a single item after IFS is changed
$ (IFS=','; x="aa bb cc"; echo "'$x'"; read a b c <<< $x;\
  echo "'$a' '$b' '$c'")
'aa bb cc'
'aa bb cc' '' ''

# Why doesn't 'read' see 3 …
Run Code Online (Sandbox Code Playgroud)

bash ifs string-parsing

2
推荐指数
1
解决办法
123
查看次数

在两个分隔符之间提取数据

我只想知道是否有可能获取两个分隔符之间存在的数据(分隔符是一个字符串).

例如,原始字符串如下

<message%20type%3D"info"%20code%3D"20005">%20<text>Conference%20successfully%20modified</text>%20<data>0117246</data>%20%20</message>%20
Run Code Online (Sandbox Code Playgroud)

我想要<text>标签之间存在的数据.我需要数据的字符串可以是不同的.字符串也可以是这样的

<message%20type%3D"info"%20code%3D"20001">%20<text>Conference%20deleted</text%20%20<vanity>0116976</vanity>%20</message>%20<message%20type%3D"info"%20code%3D"20002">%20<text>Number%20of%20conferences%20deleted</text>%20<data>1</data>%20%20</message>%20  
Run Code Online (Sandbox Code Playgroud)

但我总是需要<text>标签之间的数据.

那么在C语言中是否可能还是有其他选择?

c delimiter string-parsing

2
推荐指数
1
解决办法
5327
查看次数

Pythonic方法解析带有后缀的字符串中的数字

使用Python 3.

我有一个字符串,例如128kb/s,5mb/s或者作为简单的东西42!.数字字符及其后缀之间没有空格,所以我不能直接调用int(text).

我只是想捕捉的值128,542为整数.

目前,我刚刚编写了一个辅助函数,它将所有数字累积到一个字符串中,并打破第一个非数字字符.

def read_int_from_string(text):
    s = ""
    val = 0
    for c in text:
        if (c >= '0') and (c <= '9'):
            s += c
        else:
            break
    if s:
        val = int(s)
    return val
Run Code Online (Sandbox Code Playgroud)

以上工作正常,但有更多的pythonic方式来做到这一点

python string-parsing python-3.x

2
推荐指数
1
解决办法
131
查看次数

What is a performant way to split long lines when only a subset of fields is desired

The details of my query follow:

  1. I have a very large TSV (Tab Sep. Value) file (where large > 30 GB).
  2. I want to extract certain lines from this file that don't end with an empty last field. Since this is a TSV file, those lines that don't end with \t\n, which is a trivial test and not the subject of this question. That will remove some 75% of the lines, right off the bat, reducing the workload.
  3. Then …

csv perl text-parsing string-parsing perl5.30

2
推荐指数
1
解决办法
80
查看次数