Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:59:36+00:00 2026-06-02T14:59:36+00:00

So i’m trying to create a translator in python(in a s60 device). So what

  • 0

So i’m trying to create a translator in python(in a s60 device). So what ‘m trying to do is to replace just one whole word without touching the other words. Here’s an example

Original: “The brown fox jumps over the dog named brownie.”
I want to replace the word “brown” into “deathlesi”(Just ignore why)
The result should be:
“The deathlesi fox jumps over the dog named brownie.”
But instead it also changes “brownie” in the string which results to:
“The deathlesi fox jumps over the dog named deathlesiie.”

Since I’m trying to replace each and every word, sometimes it goes into a never ending paradox.
Example:
“I am stupid”
I’m trying to change “I” into “ium” and this is what happens.
“iumumumumumumumumumumumumumumumumumumumum…. am stupiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuim..”, it basically changes every “I” in the string and won’t stop until there’s no “I” in the string.

Any help? Thanks!

Edit: I already tried “stringhere”.replace() but certain parts like a lowercase “i” usually replaces the “i” in stupid.

Here’s another example:
“People are getting excited at the giant hare.” replacing “are” to “iume”, instead of
“People iume getting excited at the giant hare.” it also replaced “hare” which resulted into
“People iume getting excited at the giant hiume.”

Supposedly I array’ed the sentence and translate each of them.
That is my current method now. Basically converting each word into a array and converting each one of them. Then doing a

translated_sentence=["particulus:people", "iume:are", "geus:getting", "exchantus:excited", "d:at", "qun:the", "gesas:giant", "hsont:hare"]
sentence= "People are getting excited at the giant hare."
for i in translated_sentence do
element=i.split(":")
sentence=sentence.replace(element[1], element[0])

and still it throws a “particulus uime geus exchantus d qun gesas huime(instead of hsont)”

I just got it figured it out.
I just splitted the string into an array, and preserved the formatting by cleaning the current word and doing a string.replace() to the original word.

sentence="The quick brown fox jumps over the lazy dog.".split(" ")
result=""

for i in sentence:

cleaned=clean(i) #removes the punctuations and stuff leaving the raw word.

translated=translate(cleaned) #returns the translated word

result=result+i.replace(cleaned,translated)+" "

return result
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:59:37+00:00Added an answer on June 2, 2026 at 2:59 pm

    Since you only want to find the first occurrence, you just need a way to keep track of it. You can do this many ways. As simple as this:

    def replacer(original, looking_for, replace_with):
       ''' A straightforward way... '''
       return original.replace(looking_for, replace_with, 1)
       #return regex.sub(replace_with, looking_for, 1)
    

    The number indicates how many occurrences do you want to replace. If there exists two, and you put 2, both occurrences will be replaced.

    String is immutable, so you must re-assign the new string. Each time you do replace you are generating a new string.

    You can also write a loop to find the N-th occurrence if you don’t want the built-in.

    I recommend making your post shorter (I mean fewer words, and more syntax highlight). Format it.
    Correct me if I didn’t read your post correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.