这可能也很容易。但是我有这个列表视图,其中包含我列出的 exe 文件。现在,我想依次执行这些 exe 文件,从中检查或不检查哪些项目。
所以,我试过这个:
For each item in listView1.CheckedItems
Msgbox item.ToString
Next
Run Code Online (Sandbox Code Playgroud)
因为我注意到checkedItems 中的项目包含的内容不多。如果我将其转换为字符串,它最终会出现在 msgbox 中,如下所示:ListViewItem: {Filename.exe}
现在,我显然想要文件名。但是有没有其他方法可以只提取名称?或者我是否必须剥掉绳子才能将ListViewItem: {
零件取下?
在Python中,我可以从字符串中删除空格,新行或随机字符
>>> '/asdf/asdf'.strip('/')
'asdf/asdf' # Removes / from start
>>> '/asdf/asdf'.strip('/f')
'asdf/asd' # Removes / from start and f from end
>>> ' /asdf/asdf '.strip()
'/asdf/asdf' # Removes white space from start and end
>>> '/asdf/asdf'.strip('/as')
'df/asdf' # Removes /as from start
>>> '/asdf/asdf'.strip('/af')
'sdf/asd' # Removes /a from start and f from end
Run Code Online (Sandbox Code Playgroud)
但Ruby的String#strip方法不接受任何参数.我总是可以回到使用正则表达式,但有没有一种方法/方法从Ruby中的字符串(后面和前面)中删除随机字符而不使用正则表达式?
单词是一个看起来像这样的列表:
['34 ', '111110 ', '0 ', '@jjuueellzz down ']
['67 ', '111112 ', '1 ', 'Musical awareness ']
['78 ', '111114 ', '1 ', 'On Radio786 ']
['09 ', '111116 ', '0 ', 'Kapan sih lo ']
Run Code Online (Sandbox Code Playgroud)
如果你注意到列表中的每个元素后面都有一个空格,我知道我应该剥离但不知道我该怎么做.
这是我的代码:
words = line.split('\t')
Run Code Online (Sandbox Code Playgroud)
如果我这样做words = line.strip().split('\t')
- 它并没有像我想的那样正确剥离
我知道在Python中,为了让程序忽略空间你可以使用input("something").strip()
但是你用什么函数来让程序忽略空间,如果它在单词的中间,就像ja ck
有一种结合名称的方法,所以,如果你输入ja ck
它会打印出来jack
?
我正试图从右边删除一定数量的零.例如:
"10101000000"
Run Code Online (Sandbox Code Playgroud)
我想删除4个零...并得到:
"1010100"
Run Code Online (Sandbox Code Playgroud)
我试图做string.rstrip("0")
或string.strip("0")
但这删除所有零右.我怎样才能做到这一点?
问题不重复,因为我不能使用导入.
在使用 string.strip() 进行非常简单的字符串操作时,我得到了一些非常奇怪的结果。我想知道这是一个只影响我的问题(我的 python 安装有问题?)还是一个常见的错误?
这个错误是非常有线的,它是这样的:
>>> a = './omqbEXPT.pool'
>>> a.strip('./').strip('.pool')
'mqbEXPT' #the first 'o' is missing!!!
Run Code Online (Sandbox Code Playgroud)
仅当 'o' 跟在 './' 之后时才会发生!
>>> a = './xmqbEXPT.pool'
>>> a.strip('./').strip('.pool')
'xmqbEXPT'
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?!我已经在 python 2.7 和 3.5 上对此进行了测试,结果没有改变。
我有以下内容string
:
s = 'sd sdasd sas sas zxxx df xx de '
Run Code Online (Sandbox Code Playgroud)
当我使用时,
s.strip('x')
我得到以下结果:
'sd sdasd sas sas zxxx df xx de '
Run Code Online (Sandbox Code Playgroud)
为什么strip()
不删除所有'x'
字符?
我有一个 Pandas 数据框,它有一列包含字符串值和布尔值。由于这种差异,列的 dtype 推断为“对象”。当我在此列上运行 .str.strip() 时,它会将所有布尔值转换为 NaN。有谁知道我如何防止这种情况?我会同意布尔值变成字符串,但是南?
我有一个字符串
s = " \r\n Displays the unique ID number assigned to the\r\nAlias Person."
Run Code Online (Sandbox Code Playgroud)
我想删除这个起始空间,但它甚至不删除这些引号。
我试过
s = s.strip!
s = s.gsub!('"','')
Run Code Online (Sandbox Code Playgroud) 我想了解两条代码行之间的区别。我找不到区别。每当我尝试运行第二个代码时,它都不会影响字符串a。
有人能告诉我为什么第二行代码不起作用吗?
a = "aaaaIstanbulaaaa".strip('a') #Affects the string
print(a)
>>>Istanbul
Run Code Online (Sandbox Code Playgroud)
a = "aaaaIstanbulaaaa" #Doesn't affect the string
a.strip('a')
print(a)
>>>aaaaIstanbulaaaa
Run Code Online (Sandbox Code Playgroud)