Python script that can reverse Arabic text | Web Scripts | Crax

Welcome To Crax.Pro Forum!

Check our new Marketplace at Crax.Shop

   Login! SignUp Now!
  • We are in solidarity with our brothers and sisters in Palestine. Free Palestine. To learn more visit this Page

  • Crax.Pro domain has been taken down!

    Alternatives: Craxpro.io | Craxpro.com

Python script that can reverse Arabic text

Python script that can reverse Arabic text

LV
0
 

Engfree

Member
Joined
Aug 20, 2023
Threads
10
Likes
0
Awards
2
Credits
819©
Cash
0$
Code:
def reverse_arabic_text(text):
    """
    Reverses Arabic text while preserving the order of letters and words.
    
    Args:
        text (str): The Arabic text to be reversed.
        
    Returns:
        str: The reversed Arabic text.
    """
    reversed_text = ""
    words = text.split()
    
    for word in words:
        reversed_word = ""
        for char in word:
            if '\u0600' <= char <= '\u06FF':  # Check if the character is Arabic
                reversed_word = char + reversed_word
            else:
                reversed_word += char
        reversed_text = reversed_word + " " + reversed_text
    
    return reversed_text.strip()

# Usage example
arabic_text = "مرحبا بكم في عالم البرمجة"
reversed_arabic = reverse_arabic_text(arabic_text)
print(reversed_arabic)
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Top Bottom