+ 2
Specific characters removal
[15.7., 20:32] Srki: Смета [15.7., 20:32] Srki: Покрива даску [15.7., 20:32] Srki: Ролетне су довољне [15.7., 20:32] Srki: Већ 5 комплет завеса This up is the text and I want to remove the content for all from "[" to ":"so ([15.7., 20:32] Srki:) . I tried with import re but it didn't work. Thank you for help
17 Antworten
0
Hi! If I understand you, its super easy. Just put your lines in a list lst, were every element in the list is a string of your lines. Then use slice:
for i in range(len(lst)):
print(l[i][21:])
+ 2
# Hi! You can try this:
s = """[15.7., 20:32] Srki: Смета
[15.7., 20:32] Srki: Покрива даску
[15.7., 20:32] Srki: Ролетне су довољне
[15.7., 20:32] Srki: Већ 5 комплет завеса"""
sub = s[:21]
print(s.replace(sub, ""))
+ 2
It worked! Tnx man, cheers 🍻
+ 1
What data type is each line?
If string:
line = "[15.7., 20:32] Srki: Смета"
data = line.split(':')
print(data)
print(data[0])
# output
["[15.7., 20:32] Srki", "Смета"]
[15.7., 20:32] Srki
+ 1
Thanks man it works too
0
It still doesn't solve problem, I need to print out only text after "[15.7., 20:32] Srki:" so that needs to be removed.
0
I tried everything, but somehow it didn't work
0
This works but it prints out only last line
0
I need to print whole text without that what I mentioned
0
I want to make it out of a string
0
I noticed this problem when I copy multiple messages from WhatsApp and it shows date when it's sent and who sent it so I wanted to make python program who deletes it
0
It's all in one string, I wanted to make solution just to paste one whole text and to get result without that what I mentioned
0
x = "[15.7., 20:32] Srki: Смета"
h = x[21:]
print(h)
This helps only for one line
0
st="""[15.7., 20:32] Srki: Смета
[15.7., 20:32] Srki: Покрива даску
[15.7., 20:32] Srki: Ролетне су довољне
[15.7., 20:32] Srki: Већ 5 комплет завеса"""
for s in st.split("\n"):
print(s[s.rfind(":")+2:])
#try this
- 1
you can use slice and rfind method.
may not good as regex.
- 1
print(s[s.rfind(":")+1:])
- 1
Is that a single line or 4 lines of strings..? For you can use a loop..