Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace with upper(string)
#2
If the sequence is always the same, then this may do what you need:

def to_upper(text):
    output = ""
    list_text = text.split("\nd")
    for index, words in enumerate(list_text):
        word = words.lstrip("*")
        if index == 1:
            output += word.upper()
        else:
            output += word.strip()
    return output


txt = "Here is a \nd Word \nd* in upper case"
print(to_upper(txt))
txt = "This is another \nd example \nd*"
print(to_upper(txt))
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
Replace with upper(string) - by WJSwan - Feb-08-2023, 05:25 AM
RE: Replace with upper(string) - by rob101 - Feb-08-2023, 09:50 AM
RE: Replace with upper(string) - by deanhystad - Feb-08-2023, 09:23 PM
RE: Replace with upper(string) - by WJSwan - Feb-10-2023, 06:14 AM
RE: Replace with upper(string) - by deanhystad - Feb-10-2023, 06:37 AM
RE: Replace with upper(string) - by WJSwan - Feb-10-2023, 10:28 AM
RE: Replace with upper(string) - by perfringo - Feb-10-2023, 08:30 AM
RE: Replace with upper(string) - by WJSwan - Feb-10-2023, 10:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to replace a string with a file (HTML file) tester_V 1 815 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Replace string in a nested Dictianory. SpongeB0B 2 1,273 Mar-24-2023, 05:09 PM
Last Post: SpongeB0B
  Find and Replace numbers in String giddyhead 2 1,293 Jul-17-2022, 06:22 PM
Last Post: giddyhead
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 5,046 Apr-27-2022, 09:27 AM
Last Post: Anldra12
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,277 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Replace String with increasing numer [SOLVED] AlphaInc 13 5,223 Aug-07-2021, 08:16 AM
Last Post: perfringo
  How to replace on char with another in a string? korenron 3 2,405 Dec-03-2020, 07:37 AM
Last Post: korenron
  How can I add string.upper() noahneature 2 1,906 Oct-11-2020, 06:41 PM
Last Post: noahneature
  Replace string in many files in a folder metro17 8 5,714 Oct-16-2019, 06:46 PM
Last Post: ndc85430
  open, read and replace a string in a file Reims 0 1,841 Oct-02-2019, 01:30 PM
Last Post: Reims

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020