我在Powershell中有一个变量,该变量返回以下字符串
class Home extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
this.props.actions.getProgramsStart();
}
render() {
const { ProgramsLoading, programs } = this.props.state;
//check if you are loading, so you dont need to apply filters or whatever you add (filter/map creates a new array each time)
if(ProgramsLoading) return <div><Loader style={{ display: "block" }} content="Program List loading" /></div>
const defaultValue = {SeriesFilterData: [], MoviesFilterData =[]}
const reducerFunction = (accum, currentValue)=>{
//if this check is an AND for all the cases, return directly if the item doesnt match.
if(currentValue.releaseYear < 2010) return accum;
if(currentValue.programType==="series"){
accum.SeriesFilterData.push(currentValue);
} else if(currentValue.programType==="movie"){
accum.MoviesFilterData.push(currentValue);
}
return accum;
}
const results = programs.reduce( reducerFunction, defaultValue);
// using {...result} will destructure to be (SeriesFilterData, MoviesFilterData) separeted props
return (
<div id="home">
<h1>program data</h1>
<SomeComponent {...resulst} />
</div>
);
}
}
我正在尝试将该字符串格式化为类似(甚至在csv文件中)的格式:
S: Title = test S: Title = test2 S: Title = test3 S: Title = test4
TE: 2019-01-19T00:00:00Z TE: 2019-01-20T00:00:00Z TE: 2019-01-22T00:00:00Z TE: 2019-01-23T00:00:00Z
但没有成功。我该怎么办?
编辑:这是生成字符串的行。基本上,我想提取一个keepass数据库中所有条目的名称和到期日期(我可能已经找到了另一种使用导出的xml文件的方法):
test test2 test3 test4
2019-01-19 2019-01-20 2019-01-22 2019-01-23
答案 0 :(得分:0)
我必须承认.replace()
的使用有点过分,但并没有太多用处:
$mystring= " S: Title = test S: Title = test2 S: Title = test3 S: Title = test4
TE: 2019-01-19T00:00:00Z TE: 2019-01-20T00:00:00Z TE: 2019-01-22T00:00:00Z TE: 2019-01-23T00:00:00Z "
$MyString.trim().replace(" S: Title = ",",").replace("T00:00:00Z TE: ",",").replace("TE: ","").replace("S: Title = ","").replace("T00:00:00Z","").replace(" ","") | convertfrom-csv
输出:
test test2 test3 test4
---- ----- ----- -----
2019-01-19 2019-01-20 2019-01-22 2019-01-23
在创建字符串时执行这些步骤会更容易(也更容易监控)。