Re: String formats

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Joakim Karlsson (jkarlsson_at_NOSPAMjkarlsson.com)
Date: 01/19/05


Date: Wed, 19 Jan 2005 21:03:55 +0100

Try this:

using System;
class App
{
   static void Main(string[] args)
   {
     int n1 = 234;
     int n2 = 5645;

     string s1 = n1.ToString("00000");
     string s2 = n2.ToString("00000");
     int mod = int.Parse(s1+s2) % 97;

     string res = String.Format("+++{0}/{1}{2}/{3}{4}+++",
       s1.Substring(0,3), s1.Substring(3,2), s2.Substring(0,2),
       s2.Substring(2,3), mod.ToString("00"));
     Console.WriteLine(res);
   }
}

Regards,
Joakim

Jac wrote:
> Hey,
>
> Can someone help me to find a short and effective way to do the follow.
>
> I have
> Number1 as integer = 234
> Number2 as integer = 5645
>
> I want to create a string as follows (it is an obligatoire format for the
> banks):
> +++123/4567/89012+++
>
> My example :
> Number1 I want to present in a 5 char string, but left aligned with 0
> Number 2 the same
>
> as follows : 0023405645
> from that int I have to calculate the MODULO 97 = 30
>
> Now the string must be in following format
> +++002/3405/64530+++
>
> I looked in regex but don't find a good way to do it.
>
> Thanks for help.
> jac
>



Relevant Pages

  • RE: Taking fields out of a string
    ... "Jac" wrote: ... > I have a string (an document.rtf loaded in a stream and then via ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Regex : regular expression problem
    ... "Jac" wrote: ... > I want to change the string to the following with regex. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String Format
    ... For standard numeric format strings see: ... > I have an int32 and a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • String formats
    ... I want to create a string as follows (it is an obligatoire format for the ... Number1 I want to present in a 5 char string, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: String Format
    ... you don't need to parse it back to an int. ... "Jac" wrote: ... > I have an int32 and a string. ... > The string must have a lenght of 5 en must be filled up with leading zero's. ...
    (microsoft.public.dotnet.languages.csharp)