标签: strip

问号(“?”)附加到字符串

所以我正在编写一个程序并使用其他人编写的现有库。他们的库正在调用 TheMovieDatabase.com 并检索有关电影的信息,包括 Youtube 预告片名称,如“sErD7Y00R_8”。

当我调试并查看存储该值的预告片名称字符串变量时,它显示为“sErD7Y00R_8”,但是当它插入我的数据库或打印到控制台时,它似乎附加了一个?(问号)到最后,显示如下:“sErD7Y00R_8?”

这显然给我带来了一些问题。我不明白它为什么这样做以及如何解决它。我只能猜测它是一些非常规文本字符或其他东西,但这只是一个猜测。

这是包装器库的链接: https://github.com/LordMike/TMDbLib/

这是我在包装器库中调用的方法,传入 ID 143049:

TMDbLib.Objects.Movies.Movie tmdbMovie = client.GetMovie(id, MovieMethods.Credits | MovieMethods.Keywords | MovieMethods.Images | MovieMethods.Trailers | MovieMethods.Reviews | MovieMethods.Releases);
Run Code Online (Sandbox Code Playgroud)

这是之后立即打印到控制台的内容:

Console.WriteLine("'" + tmdbMovie.Trailers.Youtube[i].Source + "'");
Run Code Online (Sandbox Code Playgroud)

.Length 属性返回 12,因此它看起来是 1 个字符,它不会在调试器中显示,但会打印为 ? 在控制台中

根据评论,我打印出了 Encoding.GetBytes 详细信息:

Encoding the entire string:
System.Text.UTF7Encoding       : 20  38  :73 45 72 44 37 59 30 30 52 2B 41 46 38 2D 38 2B 49 41 34 2D 
System.Text.UTF8Encoding       : 14  39  :73 45 72 44 37 …
Run Code Online (Sandbox Code Playgroud)

c# string unicode strip

-1
推荐指数
1
解决办法
7415
查看次数

input().strip().split() 和 input().split() 有什么区别?

Split() function uses whitespace string as separator and removes the empty strings, so I think there is no use using strip() or rstrip() function to remove extra whitespace in head or tail. And here is my example:

a = ' \n   1 2 3 4     \n\n 5 \n\n \t'
b = a.rstrip().split()
c = a.split()
print('b =',b)
print('c =',c)
Run Code Online (Sandbox Code Playgroud)

The result turns out to be:

b = ['1', '2', '3', '4', '5']
c = ['1', '2', '3', '4', '5']
Run Code Online (Sandbox Code Playgroud)

It …

python split strip python-3.x

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

ValueError:long()的基数为10的无效文字:''

我如何让它工作?

n = 1234
f = open("file", "r")
while True:
 x=f.readline()
 print "*********************"
 print n%(long(x))
 if n%(long(x))==0:
   print x
else:
 print "..."
Run Code Online (Sandbox Code Playgroud)

我是python中的菜鸟,我收到一个我不明白的错误.我究竟做错了什么?

ValueError: invalid literal for long() with base 10: ''
Run Code Online (Sandbox Code Playgroud)

python newline strip

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

剥离()python的优雅方式

我必须使用Python剥离()我的数据库输出,它已经可以工作了.但有没有更优雅的方式来做到这一点?

这是我的代码:

import MySQLdb
conn= MySQLdb.connect("localhost","root","testPW","MixOMat")
c=conn.cursor()
c.execute("SELECT Zutat1 FROM Rezepte WHERE RezeptID=1")
z1=str(c.fetchall())
z1=z1.strip("(")
z1=z1.rstrip(")")
z1=z1.rstrip(",")
z1=z1.rstrip(")")
z1=z1.rstrip(",")
z1=z1.rstrip("L")
print(z1)
Run Code Online (Sandbox Code Playgroud)

python string strip

-4
推荐指数
1
解决办法
127
查看次数

从字符串中删除单引号 - “不能使用“'”(类型无类型字符串)作为类型字节”

我有一个字符串,可能会或可能不会被双引号或单引号包围。我想删除第一组引号(如果存在)。所以:

"foo" --> foo
""foo"" --> "foo"
'foo' --> foo
'foo --> foo
Run Code Online (Sandbox Code Playgroud)

等等。

我找到了这个答案,它描述了使用切片表达式来索引字符串的第一个和最后一个字符,然后如果其中一个字符是引号,则获取字符串的一部分。所以我试图调整代码以涵盖单引号和双引号:

func stripQuotes(str string) string {
    s := str[:]
    if len(s) > 0 && (s[0] == '"' || s[0] == "'") {
        s = s[1:]
    }
    if len(s) > 0 && (s[len(s)-1] == '"' || s[len(s)-1] == "'") {
        s = s[:len(s)-1]
    }

    return s
}
Run Code Online (Sandbox Code Playgroud)

但它返回一个错误:

cannot convert "'" (type untyped string) to type byte
Run Code Online (Sandbox Code Playgroud)

所以我尝试将单引号转换为字节,但这也不起作用:

...
if len(s) > 0 && (s[0] …
Run Code Online (Sandbox Code Playgroud)

string strip go

-4
推荐指数
1
解决办法
73
查看次数

为什么不剥离(",")方法不会将逗号分隔的字符串转换为python中的列表?

我有一个my_file包含两行的文件():

"002000", "WAYNE", "ROONEY", "M", 16SEP2012, 31DEC1977, 25OCT1968, 999999, "UK", "380", VOID;
"002001", "JOE", "COLE", "M", 16SEP2012, 31DEC1977, 13FEB1972, 999999, "UK", "390", VOID;
Run Code Online (Sandbox Code Playgroud)

我做:

f = open(my_file)
lines = [line.strip() for line in f]
f.close()

for line in lines:
    print line
    print type(line)

print "------------------"
for line in lines:
    print line.strip(",")
    print type(line.strip(","))
Run Code Online (Sandbox Code Playgroud)

在输出中:

"002000", "WAYNE", "ROONEY", "M", 16SEP2012, 31DEC1977, 25OCT1968, 999999, "UK", "380", VOID;
<type 'str'>
"002001", "JOE", "COLE", "M", 16SEP2012, 31DEC1977, 13FEB1972, 999999, "UK", "390", VOID; …
Run Code Online (Sandbox Code Playgroud)

python string list strip

-5
推荐指数
1
解决办法
234
查看次数

Python strip()在函数内部不起作用

我试图用来strip()修剪字符串前后的空格.它工作正常

str1 = "  abdced "
str1.strip()
Run Code Online (Sandbox Code Playgroud)

但是当我在函数中使用它时,它不起作用:

def func(str1):
    return str1.strip() 

print func("   abdwe ") 
Run Code Online (Sandbox Code Playgroud)

它不会削减任何空间.谁能说出发生了什么?谢谢!

python string strip

-5
推荐指数
1
解决办法
6266
查看次数

标签 统计

strip ×7

python ×5

string ×5

c# ×1

go ×1

list ×1

newline ×1

python-3.x ×1

split ×1

unicode ×1