473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Writing a generic function to format strings using bob.js

Hello,

Expand|Select|Wrap|Line Numbers
  1. var string = "My name is {0} and I am {1} years old."; 
  2. var result = bob.string.formatString(sFormat, "myname", 25);
I want to write a function such that I can pass the string with required number of arguments and it will return me the formatted string with all {0} , {1}, .. replaced by my passed arguments. Something like:

Expand|Select|Wrap|Line Numbers
  1. function test( string , argument1 , argument2 , ....){
  2.   return bob.string.formatString(sFormat, args);
  3. }
Apr 14 '16 #1
1 1523
Dormilich
8,658 Expert Mod 8TB
Template Literals (https://developer.mozilla.org/en-US/...plate_literals) look quite close otherwise you’d have to use String.replace().
Apr 14 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: marduk | last post by:
I have a weird request. I want to be able to say def myvalues(): while True: # stuff that determines a new somevalue yield somevalue x = "Hello, %s, this is a %s with %s and %s on top of...
3
by: Claire | last post by:
I have a large record with many enumerated fields. The record is stored in a file and the fields have to be extracted. I validate the data as it's read, but there's so many tests similar to the...
1
by: Dennis Benzinger | last post by:
Is there a library with a strftime replacement which supports Unicode format strings? Bye, Dennis
7
by: Carroll, Barry | last post by:
Greetings: Personally, I don't think top-posting is the most annoying newsgroup habit. I think it's making a big fuss about minor inconveniences. One of the nicest things about being human...
7
by: Michael Howes | last post by:
MSDN documentation for format strings seems ambiguous. It's says things like "significant digits or number of decimal places" all over the place. Well those two things are different. How do I...
3
by: anoopsr | last post by:
hI, IHave a doubt in writing a generic function in C. Say for Example, I need to add 2 numbers. 2 interger Numbers or 2 float Numbers using the same function add(). How do i call the add...
32
by: copx | last post by:
Why doesn't the C standard include generic function pointers? I use function pointers a lot and the lack of generic ones is not so cool. There is a common compiler extension (supported by GCC...
1
by: jlbfunes | last post by:
Hello, I am new to c++. I tried to create a function for doing the following: 1. Read a matrix from a .txt file 2. Store the retrieved data as a vector of vectors 3. Put the result in...
1
by: raylopez99 | last post by:
Here is an example of a home grown generic class, representing a pair of values. Adapted from Jon Skeet's book "C# In Depth". The generic class is "sealed" for some reason (I think for...
7
code green
by: code green | last post by:
I have written code that accepts orders then writes them to XML. I can create two formats of XML, one is bespoke to our CRM, the other is opXML under BOSS standards. My final createXML function...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.