format input string to xxx.xx.xx.xx

Hello  Everyone,

 Here is the issue I am working on:

input: 1 or 1.1 or 1.2.3 or 001.02.03.01

expected output in the format:

000.00.00.00

and the numbers get populated from left to right. meaning if input was 1.2, the output would/should be:

001.02.00.00

How can I do this? Regex? string.format??? This is in c#

Thanks in advance. 

 

0
tinuverma
7/23/2008 6:26:03 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
587 Views

Similar Articles

[PageSpeed] 10
Get it on Google Play
Get it on Apple App Store

You are going to have to write a method that splits up the number and builds up the number in your format.  It looks like you should split the string of numbers at each '.' and then concatenate the splits into smaller strings that you can combine to get the result looking like xxx.xx.xx.xx


Tommy
0
tommyk
7/23/2008 7:14:06 PM

I was hoping if there was a more direct way using Regex....and I have no idea of regex...so dont know if its even possible using it.

Thanks for ur quick response.

0
tinuverma
7/23/2008 7:16:36 PM

Please try this function

protected string formatInput(string input)
{
     
string output = "";
     
string[] nums = input.Split('.');
     
switch (nums.Length)
      {
       
case 1:
          output =
string.Format("{0,4:D4}.00.00.00", int.Parse(nums[0]));
          
break;
     
case 2:
          output =
string.Format("{0,4:D4}.{1,2:D2}.00.00", int.Parse(nums[0]), int.Parse(nums[1]));
        
break;
     case 3:
          output =
string.Format("{0,4:D4}.{1,2:D2}.{2,2:D2}.00", int.Parse(nums[0]), int.Parse(nums[1]), int.Parse(nums[2]));
          break;
     case 4:
          output =
string.Format("{0,4:D4}.{1,2:D2}.{2,2:D2}.{3,2:D2}", int.Parse(nums[0]), int.Parse(nums[1]), int.Parse(nums[2]), int.Parse(nums[3]));
          break;
   
default:
  
//invalid string
             
break;
     }
     return output;
}

 

Let me know how it goes.


Thanks,
Ritesh

---------------------------------------------
Please do not forget to mark as Answer if my reply is helpful.
0
aadreja
7/23/2008 7:32:20 PM
Reply:

Similar Artilces:

/MH-xx.xx.xx.xx
I use Verizon DSL and they require a username/password to use their outgoing smtp server. Too many hosts reject my e-mail because of my dynamic IP. Does GW6.5 allow a username/pswd combo to log in to an ISP's SMTP server? Hi, Tried looking at the Dial-up settings on the SMTP tab of the GWIA properties? Mike > I use Verizon DSL and they require a username/password to use their outgoing > smtp server. Too many hosts reject my e-mail because of my dynamic IP. > Does GW6.5 allow a username/pswd combo to log in to an ISP's SMTP server? > > Michael...

zisedit DNSServer1=xx.xx.xx.xx
I recently installed the Zenworks 7 SP1 HP2 and modified the bootcd for our environment. I use a script to change the ZISD on the machine, this is the tail end of my past script for setting the DNS Servers: zisedit DNSServerCount=4 zisedit DNSServer1=35.8.208.41 zisedit DNSServer2=35.8.2.41 zisedit DNSServer3=35.8.2.42 zisedit DNSServer4=35.8.98.43 This worked fine without HP2. However, when using the HP2 bootcd `zisedit DNSServer1=35.8.208.41` outputs the error: Unknown parameter (0): 'DNSServer1=35.8.208.41' I've been searching through forums and even the or...

Send Failure: 421 mails from xx.xx.xx.xx refused: local dynamic IP address xx.xx.xx.xx
--____WVRGWAXLCBHMONRQBWTO____ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Wed, 5 Jun 2007 06:54:16 -0400" We are running GW 7.01 and have been for about 3 months. This problem = first surfaced about 2 weeks ago. Our dns records are correct, but this = one ISP that hosts email for several of our customers is rejecting our = mail for the above reason. They are claiming we have an invalid configurat= ion, but no one else rejects email from us because of this. They claim we = ...

Construction of SA failed for peer xx.xx.xx.xx
Hi, We use BM37 for site-to-site VPN. On the slave's audit log, we got such message: (SKIP) Constuction of SA failed for peer xx.xx.xx.xx The IP adress is the ip of hosts behind the vpn slave. The audit message has explanation: "IPSEC failed to set up a Security Association with the indicated connection causing packets to be dropped.", and has Action suggestion: check for possible out of memory conditions. The server we used is a brand new with a few GB RAM. The action seems making no senses for me. I tried to search the KB, found nothing. Any sugges...

(SKIP) Construction of SA failed for peer xx.xx.xx.xx
I am trying to setup a new SITE to SITE VPN connection. Yesterday, SBC installed SBC Yahoo DSL. I told the installer that I did not want DHCP, filters, or NAT, so he suggested I used a bridge and not a router for the service. He installed an Efficient Networks SpeedStream 5360. Internet service is working and the BM 3.7 proxy server is working for HTTP. My problem: When trying to establish a connection for the Site to Site, the Slave server reports: Audit Log: (SKIP) Construction of SA failed for peer 68.xx.xx.xx Info: IP Security Error 284 IPSEC fa...

(SKIP) Construction of SA failed for peer xx.xx.xx.xx #2
Hi, some time ago i tested VPN server to server connection, for server with address 172.22.81.189(Master1) it was OK. Than I removed VPN configuration on Slave1 server and from NWAdmin on Master(172.22.81.189). Today I created VPN server to server with same server which was Slave before, but now it is a Master2 server. I have also new Slave2 server and when I look in Audit via NWAdmin there are lines (SKIP) Construction of SA failed for peer 172.22.81.189 but this server is no longer member of this VPN !!! Could somebody tell me wher could be this info saved? Thanks Ale...

https://xx.xx.xx.xx/BM-Login/?"http://yourwebsite
I am having a problem after reinstalling netware enterprise webserver 3.5.2 from the nw51 cd. Starting your webbrowser there is no automatic redirection to the BM-Login page. When typing it by hand it's working ok. Idea's we are running netware 5.1 sp6 BM 3.6 sp2a Evert In article <KQF2d.13063$oo4.7807@prv-forum2.provo.novell.com>, wrote: > Starting your webbrowser there is no automatic > redirection to the BM-Login page. When typing it by hand it's working ok. > What do you mean, 'typing it by hand'? If you are looking for the SSL Prox...

ERROR: "client xx.xx.xx.xx#xxxx: update 'zone name/IN' deni
Seeing this error on DNS console. TID 10086933 option 3 says Go to the Control List for the zone affected and add the ip address of the device trying to update DNS in the "Allow Update" list. However there is no such 'Control List' option in the DHCP console. Where do I find it? Thanks Lenny -- lennyd ------------------------------------------------------------------------ Lenny, > However there is no such 'Control List' option in the DHCP console. > Where do I find it? What version of the DNS/DHCP console are you using? Wi...

421 4.7.0 [TS02] Messages from xx.xx.xx.xx temporarily deferred due to user complaints
--____QNBRMLBZKGHSTVVBHGKM____ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Sat, 11 Apr 2008 04:50:38 -0400" We are running GW 7.0.1. We have been seeing this error for about 3 days. = Does anyone have any idea if there is anything I can do to stop these = errors? It is causing our customer service problems discussing customer = instructions. This can cause us to miss deadlines or to make mistakes. 03:18:20 326 DMN: MSG 45893 Send Failure: 421 4.7.0 [TS02] Messages from = ...

data format string for xx,xxx
Hi, Anyone know of the data format string to get an integer to appear with commas but without any places to right of the deciaml place? i.e. 12345 ==> 12,345 TIA, Dave Hi Dave,If understand your question correctly a custom number format string should do the trick:int myInt = 1234567;Response.Write(myInt.ToString("#,#"));(Assuming the culture of your application's running thread is one where a ',' character is the thousand separator. Like in "en-US", for instance.)-- Tarjei...

OBJECT_NOT_EXIST (Session/lookup
I have a test cluster with two servers and one of the servers lease expired. I have installed the same version of Jaguar as the other server in the cluster and the servers have the same name and listeners, when I tried syncing the cluster to the new server ( which kept the old servers name and ip) I started getting the SystemException: OBJECT_NOT_EXIST (Session/lookup - @XXX.XX.X.XX) message whenever the server was called. I have tried deleting the cluster and recreating it and that didn't help. I have tried syncing from the new server making it the primary and that seems to have...

ValidationExpression URL allow http://xxx.xx?xx=x
I have ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?" I would just like to allow not having a slash before a question mark in a URL. I have the list of the Regular Expression Syntax (JScript), but I think it is really complicated to change anything. If I just have ValidationExpression="http://" I still are not allowed to have a link like http://tni.dk?ref=1506764. Can anybody help?Jørgen A.J. ...

Mailer-Daemon@xxx.xxxxxxx.xx.xx (user not found)
Hi! We are using GW5.5. During the last days, me (postmaster) and ADMIN are receiving every 1-3 seconds mails same as the following one. Please help to stop this avalanche. TIA Nanu ------------- The mail example --------------------------------------- MAIL FROM:<admin@frogo.bezeqint.net> RCPT TO:<Mailer-Daemon@mail.kalmanovitz.co.il> Received: from frogo.bezeqint.net by mail.kalmanovitz.co.il; Tue, 25 May 2004 10:57:15 +0300 To: Mailer-Daemon@mail.kalmanovitz.co.il From: admin@frogo.bezeqint.net Subject: Returned mail: unreachable recipients: admin@frog...

Mailer-Daemon@xxx.xxxxx.xx.xx (user not found)
Hi! I know that GW5.5 is out dated but maybe any of you can help, or maybe the problem exist in 6.x versions too. During the last days, me (postmaster) and ADMIN are receiving every 1-3 seconds mails same as the following one. Please help to stop this avalanche. TIA Nanu > ------------- The mail example --------------------------------------- > > MAIL FROM:<admin@frogo.bezeqint.net> > RCPT TO:<Mailer-Daemon@mail.kalmanovitz.co.il> > Received: from frogo.bezeqint.net > by mail.kalmanovitz.co.il; Tue, 25 May 2004 10:57:15 +0300 ...

Web resources about - format input string to xxx.xx.xx.xx - asp.net.getting-started

Format - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

GOP candidates split on approach to change debate format - Videos - CBS News
Ben Carson leads Donald Trump and the rest of the Republican field in another national poll. It comes as some candidates are rejecting a new ...

Retro video format Betamax finally dies
It might be a surprise to many, but Sony has finally killed off its analogue video format Betamax.

Sony is finally killing its ancient Betamax format
Forty years after it was first introduced, Sony is finally putting Betamax out of its misery.

Kohl’s Opening Smaller-Format Stores, More Outlet Locations As Part Of Turnaround Efforts
... bring struggling sales numbers up, Kohl’s is betting on two new kinds of stores: the company announced plans to open a number of smaller-format ...

Christie Criticizes Upcoming Debate Format For Ignoring New Hampshire Voters
'I'll be in Milwaukee tomorrow night and I'll be on the stage where I'll get a lot more time to talk'

BBC Cuts Will Result In Comedy, Sports Casualties; ‘Voice’ Savings To Go To New Formats
A shortfall in funding at the BBC means the corporation is being forced to cut £150M in expenditure by 2017. The deficit stems from an increasing ...

Reuters: photos must use compressed format to 'reflect reality'
News agency Reuters will no longer accept photos shot in the RAW format, saying its freelancers are now required to submit JPEG photos shot in-camera. ...

Elle King And The Slow Climb Of Crossing Radio Formats
I think I’d like to be Elle King’s best friend. It’s 2pm in the UK and King is in a van driving through a town she doesn’t know the name of, ...

DEBATE REVOLT? GOP candidates consider format shift, excluding RNC
DEBATE REVOLT? GOP candidates consider format shift, excluding RNC

Resources last updated: 11/22/2015 9:45:04 AM