Deluge | Program to reverse String Without using built-in function

Deluge | Program to reverse String Without using built-in function

If you've been working with Zoho's Deluge scripting language, you've probably noticed it strikes a nice balance between simplicity and real power. String manipulation is one of the most common tasks in any scripting language — and reversing a string is a classic problem that reveals a lot about how a language handles iteration, data structures, and built-in utilities. In this article, we walk through three distinct approaches to reverse a string in Deluge, each teaching you something new about the language.

What Is String Reversal?

String reversal is the process of rearranging the characters of a string so that they appear in the exact opposite order — the last character becomes the first, the second-to-last becomes the second, and so on until the whole string is flipped.

  • Original: Zohocrm — characters run Z → o → h → o → c → r → m
  • Reversed: mrcohoZ — characters run m → r → c → o → h → o → Z
  • Every character stays the same — only their positions are swapped. Nothing is added or removed.
  • Reversing a string twice always gives back the original: reverse(reverse("Zohocrm")) = "Zohocrm"

Think of it like reading a sentence from right to left instead of left to right. The letters themselves don't change — you're just changing the direction in which you read them. In programming, this is one of the most foundational string operations, used everywhere from data validation to algorithm design.

What Is Deluge?

Deluge (Data Enriched Language for the Universal Grid Environment) is Zoho's proprietary scripting language, built specifically for automating tasks across Zoho's suite of business applications — including Zoho CRM, Zoho Creator, Zoho Books, Zoho Desk, and more.

  • It is a high-level, dynamically-typed language with a syntax that feels approachable even for non-programmers.
  • Deluge runs server-side inside Zoho's cloud infrastructure — no setup, no compilation, no deployment needed.
  • It supports all common programming constructs: variables, loops, conditionals, functions, lists, and maps.
  • It comes packed with built-in functions for string manipulation, date handling, HTTP calls, and database interactions.
  • Scripts written in Deluge are called functions and can be triggered by user actions, scheduled automations, or workflow rules inside any Zoho app.

String manipulation — like reversing, trimming, splitting, or searching within strings — is a core Deluge skill because so much of CRM and business automation work involves cleaning, formatting, and transforming text data coming from forms, APIs, and user inputs.

Real-World Use Cases for String Reversal

You might be wondering — when would I actually need to reverse a string in a Zoho workflow? More often than you'd expect. Here are the most common real-world scenarios:

🔁
Palindrome Detection

Checking whether a customer-entered code or ID reads the same forwards and backwards — useful for validating special promo codes or license keys.

🔓
Decoding Third-Party IDs

Some external systems encode identifiers by reversing them. Deluge scripts that integrate with these platforms need to reverse the string back to get the original value.

Data Integrity Checks

Comparing a string against its reverse is a quick sanity check in ETL pipelines moving data between Zoho and external platforms.

🔍
Suffix Pattern Matching

Reversing a string lets you search for suffix patterns as if they were prefixes — handy for file names, SKUs, or product codes where meaning is encoded at the end.

🛡️
Light Obfuscation

Simple (non-security-critical) obfuscation of internal reference codes before displaying them in customer-facing views.

📚
Learning & Interview Prep

String reversal is a foundational practice problem that teaches loops, lists, and string concatenation — core Deluge building blocks used everywhere.


Example for this guide

Input
Zohocrm
Expected Output
mrcohoZ

We'll use Zohocrm as our example throughout. All three methods below should produce the same result: mrcohoZ. Let's go through each one.

1 Manual Loop — Without reverse()

This is the most instructive approach because it forces you to think character by character. Instead of relying on any built-in utility, we iterate through each character and prepend it to a result string. The trick is simple: if you always place the newest character at the front, by the time you're done the string has been read backwards.

Deluge
var = "Zohocrm";
result = "";

for each e in var.toList("")
{
    // Prepend each character in front of the existing string
    result = e + result;
}

info result;
Output → mrcohoZ
How It Works
  • var.toList("") splits the string into a list of individual characters. Passing an empty string as delimiter means "split at every character."
  • The loop visits each character left to right: Z, then o, then h, and so on.
  • Each character is placed before the existing result. After the 1st iteration: "Z". After the 2nd: "oZ". After the 3rd: "hoZ"… and so on.
  • By the end of the loop, the result is the fully reversed string: mrcohoZ.

This method is especially valuable when you want to understand reversal from first principles, or when you're in an environment that restricts certain built-in functions. It's also a classic interview question answer — explaining the prepend trick signals a solid grasp of string operations.

2 Using the reverse() Built-in Function

If you just need to get the job done quickly and cleanly, Deluge makes it easy with the built-in reverse() method. It is a native string function that returns the reversed version of any string in a single call — no loops, no extra variables.

Deluge
var = "Zohocrm";
result = var.reverse();

info result;
Output → mrcohoZ
When to Use This
  • Use reverse() whenever readability and brevity are priorities. It tells the reader exactly what's happening at a glance.
  • It is internally optimized and handles edge cases — like an empty string or a single character — gracefully and without errors.
  • Perfect for production Deluge functions where string reversal is part of a larger workflow: customer ID parsing, data transformation, CRM field manipulation, etc.

This is the recommended approach for most everyday Deluge work. Two lines of code, no room for bugs, and perfectly readable. There's no justification for the manual approach when reverse() is available and the goal is simply to reverse a string.

3 Using a Stack (Last-In, First-Out)

This is the most interesting approach from a computer science perspective. A stack is a data structure that follows the Last-In, First-Out (LIFO) principle — the last item pushed onto the stack is always the first one to come off. That property makes stacks a natural tool for reversing sequences of any kind.

In Deluge, we simulate a stack using a list. We push all characters onto the list, then read them from the end (the top of the stack) backwards:

Deluge
var = "Zohocrm";
myList = list();
final = "";

// Phase 1: Push every character onto the stack
for each el in var.toList("")
{
    myList.add(el);
}

info "Stack: " + myList;

// Phase 2: Pop from the top (read from end to start)
for each index i in myList
{
    final = final + myList.get(myList.size() - (i + 1));
    // Gets: last element first, then second-to-last, etc.
}

info final;
Output → mrcohoZ
Visualizing the Stack
Characters pushed onto the stack (top = last pushed)
▲ TOP — popped first
m
r
c
o
h
o
Z  — pushed first
How It Works
  • Phase 1 — Push: We iterate through the string and add each character to myList. After this phase: [Z, o, h, o, c, r, m].
  • Phase 2 — Pop: We use the index formula myList.size() - (i + 1) to access elements from the end of the list backwards. At i=0, we get m. At i=1, we get r. At i=2, we get c, and so on.
  • Concatenating those gives us: mrcohoZ — the reversed string.

The stack approach might feel like overkill for simple string reversal, but it becomes essential for more complex problems — validating parentheses, processing arithmetic expressions, or building undo systems. Learning it in this straightforward context makes it much easier to apply when the stakes are higher.


Quick Comparison
Method Code Lines Readability Best For
Manual Loop ~6 Moderate Learning the fundamentals
reverse() built-in 2 Excellent Production scripts, everyday use
Stack (LIFO) ~12 Verbose CS concept demos, complex logic

Conclusion

Reversing a string is a deceptively simple problem that opens the door to understanding loops, data structures, and built-in APIs in Deluge. Whether you pick the manual loop for its transparency, the reverse() built-in for its elegance, or the stack approach for its conceptual richness — each method gives you a different lens through which to understand how Deluge handles data.

For most real-world Zoho CRM workflows, the built-in reverse() function is your best friend. But keeping all three approaches in your toolkit will make you a more versatile and confident Deluge developer — and that's always worth the extra few minutes of learning.

Post a Comment