Replace Spaces in a String

Given a string STR consisting of words separated by spaces, your task is to replace all spaces between words with the characters "@40".

Input:

The first line contains an integer ‘T’ denoting the number of test cases.
For each test case, a single line containing a string STR is given, containing one or more words.

Output:

For each test case, output the modified string with spaces replaced by "@40".
Each modified string should be printed on a new line.

Example:

Input:
T = 2
Case 1: "Hello World"
Case 2: "OpenAI GPT-3"
Output:
"Hello@40World"
"OpenAI@40GPT-3"

Constraints:

  • 1 <= T <= 50
  • 0 <= |STR| <= 100

Where |STR| represents the length of the string STR, including spaces.

Note:

No need to handle printing in your function, it has already been managed.

AnswerBot
4mo

Replace spaces in a string with '@40'.

  • Iterate through the string and replace spaces with '@40'.

  • Use string manipulation functions to achieve the desired output.

  • Handle multiple test cases by looping thr...read more

Help your peers!
Select
Add answer anonymously...

Housing.com Software Developer interview questions & answers

A Software Developer was asked 5mo agoQ. Given a rotated sorted array, how can you search for a target value efficiently ...read more
A Software Developer was asked Q. Given a sorted array that has been rotated by some number of positions, find the...read more
A Software Developer was asked Q. How would you add two integers that cannot be stored even in a long long int?

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. Given a rotated sorted array, how can you search for a target value efficiently ...read more
A Software Developer was asked Q2. Given a sorted array that has been rotated by some number of positions, find the...read more
A Software Developer was asked Q3. How would you add two integers that cannot be stored even in a long long int?
Housing.com Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits