Hi
I have a string which is at least 4 characters but can be more which I need
to pad, with zeros, to a full length of 15 after the 3rd charactor.
Eg '1234' to '12300000000000 4'
How can I do this?
Also how can I truncate this back to 4 or however many charactors (e.g.
123000000000400 = 123400)
Any help will be much appreciated
Thanks
B 10 2635
"Ben" <Be*@NoSpam.com > schrieb im Newsbeitrag
news:up******** ******@TK2MSFTN GP12.phx.gbl... Hi
I have a string which is at least 4 characters but can be more which I
need to pad, with zeros, to a full length of 15 after the 3rd charactor.
Eg '1234' to '12300000000000 4'
How can I do this?
1. split the string into "123" and "4" (check out String.Substrin g())
2. pad the second string (check out String.PadLeft( ))
3. concatenate the two string (check out String.Concat() )
Also how can I truncate this back to 4 or however many charactors (e.g. 123000000000400 = 123400)
remove the 4th character from your string (check out String.Remove() ) while
it equals "0" (while loop with String.Equals() ).
If you want to improve your knowledge on algorithms, i suggest the books by
Robert Sedgewick.
Diana,
"Diana Mueller" <diana@nospam > schrieb: 3. concatenate the two string (check out String.Concat() )
I suggest to use the '&' operator for string concatenation instead of using
'String.Concat' .
If you want to improve your knowledge on algorithms, i suggest the books by Robert Sedgewick.
Full ACK!
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Diana,
"Diana Mueller" <diana@nospam > schrieb: 3. concatenate the two string (check out String.Concat() )
I suggest to use the '&' operator for string concatenation instead of using
'String.Concat' .
If you want to improve your knowledge on algorithms, i suggest the books by Robert Sedgewick.
Full ACK!
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im Newsbeitrag
news:OS******** ******@TK2MSFTN GP14.phx.gbl... I suggest to use the '&' operator for string concatenation instead of
using 'String.Concat' .
Why is that preferable?
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im Newsbeitrag
news:OS******** ******@TK2MSFTN GP14.phx.gbl... I suggest to use the '&' operator for string concatenation instead of
using 'String.Concat' .
Why is that preferable?
Diana,
"Diana Mueller" <diana@nospam > schrieb: I suggest to use the '&' operator for string concatenation instead of using 'String.Concat' .
Why is that preferable?
Readability is better when using '&':
\\\
Dim s As String =
"Hello " & Name & "," & ControlChars.Ne wLine
///
vs.
\\\
Dim s As String = _
String.Concat(" Hello ", Name, ",", ControlChars.Ne wLine)
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Diana,
"Diana Mueller" <diana@nospam > schrieb: I suggest to use the '&' operator for string concatenation instead of using 'String.Concat' .
Why is that preferable?
Readability is better when using '&':
\\\
Dim s As String =
"Hello " & Name & "," & ControlChars.Ne wLine
///
vs.
\\\
Dim s As String = _
String.Concat(" Hello ", Name, ",", ControlChars.Ne wLine)
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Diana,
In addition to readability as Herfried suggests, the & operator will
concatenate any constants at compile time. String.Concat is strictly a
runtime function.
Const format As String = "Hello" & ControlChars.Ne wLine & "World"
When dealing with Object variables (parameters really) & Option Strict On
String.Concat is useful:
Option Strict On
Dim i1 As Object = 1
Dim f1 As Object = 1.0F
Dim d1 As Object = 100D
Dim s1 As Object = "help"
Debug.WriteLine (i1 & f1 & d1 & s1)
Debug.WriteLine (String.Concat( i1, f1, d1, s1))
The first statement is a compile error, while the second succeeds, both
should return the same result! As String.Concat is overloaded for both
String & Object!
Hope this helps
Jay
"Diana Mueller" <diana@nospam > wrote in message
news:un******** ******@TK2MSFTN GP14.phx.gbl... "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im Newsbeitrag news:OS******** ******@TK2MSFTN GP14.phx.gbl... I suggest to use the '&' operator for string concatenation instead of using 'String.Concat' .
Why is that preferable?
Diana,
In addition to readability as Herfried suggests, the & operator will
concatenate any constants at compile time. String.Concat is strictly a
runtime function.
Const format As String = "Hello" & ControlChars.Ne wLine & "World"
When dealing with Object variables (parameters really) & Option Strict On
String.Concat is useful:
Option Strict On
Dim i1 As Object = 1
Dim f1 As Object = 1.0F
Dim d1 As Object = 100D
Dim s1 As Object = "help"
Debug.WriteLine (i1 & f1 & d1 & s1)
Debug.WriteLine (String.Concat( i1, f1, d1, s1))
The first statement is a compile error, while the second succeeds, both
should return the same result! As String.Concat is overloaded for both
String & Object!
Hope this helps
Jay
"Diana Mueller" <diana@nospam > wrote in message
news:un******** ******@TK2MSFTN GP14.phx.gbl... "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb im Newsbeitrag news:OS******** ******@TK2MSFTN GP14.phx.gbl... I suggest to use the '&' operator for string concatenation instead of using 'String.Concat' .
Why is that preferable?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul E Collins |
last post by:
Given a string variable (form input), how can I determine whether it
represents a valid integer?
is_numeric is true for floats as well as integers, and is_int always
fails on a string.
P.
|
by: __PPS__ |
last post by:
Hello,
I have a function that does some decoding (same as urldecode in php)
and it returns std::string
std::string urldecode(const char* in, std::size_t length);
so, this function parses input and constructes output char by char. I
tried to use all sorts of direct access to the buffer of std::string to
be returned but it's always slow. It appered that if I dynamically
allocate memory fill it with output, then create std::string from this...
|
by: Olivier Bellemare |
last post by:
I've tried to make a function that returns the middle of a string. For
example:
strmid("this is a text",6,4); would return "is a".
Here is my code:
char *strmid(char *texte, int depart, int longueur)
{ char *resultat = " ";
char *temporaire = " ";
int nbr;
|
by: Yang Lee |
last post by:
hi
is this correct
char teststr="\0";
or is there another method to initialise;
thanks
lee
|
by: Opa |
last post by:
I have a string with n number of characters. I'm trying to create another string which is exactly 12 characters having leadings zeros and the input string at the end
ex: string1 = "7344", I want to format string1 such that it results another string with string1 at the end and leading zeros in front of it like: "000000007344
so I try string2=String.Format(??????,string1
does anyone know the correct formatting expression
Thank
| |
by: Ben |
last post by:
Hi
I have a string which is at least 4 characters but can be more which I need
to pad, with zeros, to a full length of 15 after the 3rd charactor.
Eg '1234' to '123000000000004'
How can I do this?
Also how can I truncate this back to 4 or however many charactors (e.g.
|
by: karthi |
last post by:
hi,
I need user defined function that converts string to float in c.
since the library function atof and strtod occupies large space in
my processor memory I can't use it in my code.
regards,
Karthi
|
by: Rich Raffenetti |
last post by:
How can one format an integer into a hex string with leading zeros? Suppose
an integer is 512 which in Hex is 200. I wish to print the 4-byte integer
as 0200 or even 0x0200. The HEX function doesn't create leading zeros. The
Format function (format(value,"X") doesn't create leading zeros.
I believe there should be a simple way that doesn't involving measuring and
padding the string.
|
by: ram23 |
last post by:
Hi friends,
i need help ..
i am getting String value and i need to add leading zeros..
total length of Target string is 13char
eg: suppose if i get 12 as values..
it needs to convert into 0000000000012
|
by: =?Utf-8?B?SExvbmc=?= |
last post by:
Could someone give a hand on how to handle this issue: I need to find a way
of removing zeros from files names. The zeros in the names are used to sort
the file name, e.g. MAK0080.pci, MAK-0080.pci. What I need to do is to
remove the zeros, so the file names become MAK80.pci o MAK-80.pci. I have
done something in Visual Basic using the Mid() function and going thru the
string removing the zeros. Is there a better way of doing this,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |