字符串&数组的相互转换

字符串 -> 数组

方法一:

$str = "abcd"

$s2 = $str.GetEnumerator()  #$s2是无法使用下标的方式进行索引的,因为其不是array

$s2  | % {$_ + "y8y"}

$str = "abcd"

Foreach ($s in $str.GetEnumerator()) {$s + "y8y"}

方法二:

$str = "abcd"

$str.tochararray()

输出结果:

ay8y

by8y

cy8y

dy8y

数组 -> 字符串

方法一:

$info = ‘One‘, ‘Two‘, ‘Three‘

$info | Out-String

方法二:

$info = Get-Content $env:windir\windowsupdate.log -Raw

参考:

http://blog.vichamp.com/powershell/tip/2014/05/19/converting-text-arrays-to-string

http://www.cnblogs.com/dreamer-fish/p/3942023.html

时间: 2024-08-27 15:05:39

字符串&数组的相互转换的相关文章

javascript中字符串和数组的相互转换

javascript中字符串和数组的相互转换:字符串和数组的相互转换操作是非常的重要的,因为在实际编码过程中会经常用到,所以这是必须要掌握的知识点,当然这个知识点并不难,知道了就永远知道了,并不是那种需要充分实践才能够掌握的东西,下面就做一下简单的介绍.一.字符串转换为数组:此操作会用到split()函数,它能够以指定的字符作为分隔符,将字符串转换成一个数组,实例代码如下: var Str="abc-mng-zhang-mayi"; var newArray=Str.split(&qu

字符串数组中两个字符的最短距离

[leetcode] https://leetcode.com/problems/shortest-word-distance/ For example,Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Given word1 = "coding", word2 = "practic

Java求字符串数组交集 并集 差集 去重复并集

//系统方法 package com; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Test { public static void main(String[] args) { List list1 =new ArrayList(); list1.add("1111"); list1.add("2222"); list1.add

关于清空字符串数组

嗯,由于要多次输出某字符串数组,比如str[100], 所以,每次输出完之后需要对其进行重置╮( ̄▽ ̄)╭ 可以使用如下的函数: menset(str, 0, 100); 嗯,一共三个参数,很容易看明白哇 <( ̄︶ ̄)/ 度娘上是这么评价的: memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法!╰( ̄▽ ̄)╯

利用快慢下标操作字符串数组

1.去除掉多余的空格: e.g. Before:   Life___is__short___I___use___python_'\0'(下划线为空格) After:  Life_is_short_I_use_python'\0' (去除掉多余的空格) 去掉空格比较简单,我们可以通过逐个判断字符,如果有连续的空格就使数组左移直到只剩一个空格,可是这么做效率十分低下; 前面学习过利用快慢下标的方法实现快排思想,这里也可以采用类似的方法 : 对于删除后的数组,长度将减少或者不变,则指向删除后数组的下标

Android中资源文件中的字符串数组string-array简单用法

在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例子如下: 把相应的数据放到values文件夹的strings.xml文件里,或是其他自定义的xml中都可以,以下操作方法相同. <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="sports"> <item>足球<

本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并打印输出。

/** * Homework14 * * @Description:本程序找出字符串数组 String[] arr = {"welcome", "china", "hi", * "congratulation", "great"} 中的长度最大的元素,并打印输出. * StringDemo01 * * @author  * * email: [email protected] 2017年4月18日下午6:3

iOS开发入门 ? C语言(字符串、字符串数组、命令行参数)

字符串 1. 概念 用双引号引起来的就是字符串 "a string" //C语言编译器会将两个并列的字符串自动拼接成一个字符串 "a string""another a string" // \是换行连接的标记(一行不够写) "a looooooooooong \ string" 常见ASCII编码: 'A' == 65    'a' == 97    '0' == 48    '\0' == 0 int a[10]; //表

利用char, str2mat, strvcat创建多行字符串数组

用专门函数char , str2mat , strvcat创建多行字符串数组示例. 1.char('str1', 'str2',...) Convert to character array (string)转换成字符串数组,空字符串是有效的. 示例:S1=char('This string array','', 'has two rows.')   S1 = This string array has two rows. 2.str2mat  (新版本中被char替代) Form blank-