$line
和$lines
之间有什么区别?
PS /home/nicholas/power_shell> $line = Get-Content ./line.txt
PS /home/nicholas/power_shell> $line
1 2 3
PS /home/nicholas/power_shell> $line[3]
PS /home/nicholas/power_shell> $line[2]
1 2 3
PS /home/nicholas/power_shell> $line.Length
5
PS /home/nicholas/power_shell> $lines = Get-Content ./lines.txt
PS /home/nicholas/power_shell> $lines
1
2
3
PS /home/nicholas/power_shell> $lines.Length
7
PS /home/nicholas/power_shell> $lines[4]
3
PS /home/nicholas/power_shell> $lines[3]
2
PS /home/nicholas/power_shell>
如何访问$line
中的各个号码?具体来说,获取$line[i]
编号。即,位于指定索引处的元素。然而,$line
并不像$lines
那样是一个数组
per Mathias:
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $lines = Get-Content ./lines.txt
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $lines
1
2
3
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $line = Get-Content ./line.txt
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $line
1 2 3
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> -split $line
1
2
3
PS /home/nicholas/power_shell>
不确定这是bash命令还是powershell命令,但很有趣。thx。
这种方式对我来说更有意义:
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $line.split()
1
2
3
PS /home/nicholas/power_shell>
然而,当我使用选项卡完成来查看可用选项时:
PS /home/nicholas/power_shell>
PS /home/nicholas/power_shell> $line.
Count LongLength Clear Equals GetLongLength IndexOf Set ForEach
IsFixedSize Rank Clone Get GetLowerBound Initialize SetValue
IsReadOnly SyncRoot CompareTo GetEnumerator GetType Insert ToString
IsSynchronized Add Contains GetHashCode GetUpperBound Remove Item
Length Address CopyTo GetLength GetValue RemoveAt Where
PS /home/nicholas/power_shell> $line.
CCD_ 7函数(它是函数吗?(没有列出。