473,320 Members | 2,092 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,320 software developers and data experts.

a way to ignore the rest of a string after a certain character??

20
Hi guys, is there anything i can do to only read a certain part of a string, im reading an IP, but the IP contains the port like 127.0.0.1:80, but i dont want to include the ":80". i cant tell it how long the string is because the IP's change and the lengh varies. so i need to ignore anything after " : ".

Thanks
Mar 2 '09 #1
4 2546
PRR
750 Expert 512MB
you could use indexof and substring method (for short strings)...
Expand|Select|Wrap|Line Numbers
  1. string filterChar = ":";
  2.                 string myLongString = @"Some where rrr :  sdfsdf";
  3.                 int inde = myLongString.IndexOf(":");
  4.                 if (inde > 0)// or not equal to -1 will do 
  5.                 {
  6.                     string myShortString = myLongString.Substring(0, inde - 1);
  7.                 }
  8.  
A better approach would be regular expression for larger string ...
Mar 2 '09 #2
USBZ0r
20
Thanks deepblue, appreciate it!
Mar 2 '09 #3
jg007
283 100+
only just learning regex's but this seems to work , I am getting the value from textbox1 to test it

Expand|Select|Wrap|Line Numbers
  1.  
  2. string RegexMatchString = @"(?<IP>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})";
  3.             Regex testr = new Regex(RegexMatchString);
  4.             Match matx = testr.Match(textBox1.Text);
  5.             MessageBox.Show(matx.Groups["IP"].Value);
  6.  
  7.  
Mar 2 '09 #4
jg007
283 100+
a bit simpler -

Expand|Select|Wrap|Line Numbers
  1.  
  2.             string RegexMatchString = @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}";
  3.             Regex testr = new Regex(RegexMatchString);
  4.             MessageBox.Show(testr.Match(textBox1.Text).Value) ;
  5.  
  6.  
  7.  
Mar 2 '09 #5

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

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
5
by: Luis | last post by:
Please help, this is due at 11:59 PM tonite. Thanks Write a program that reads a person's name from the keyboard in the format First Middle Last. It should then (1) print each of the names on...
3
by: macgyver | last post by:
This is a strange question, and I think the answer is NO, but I am asking anyway. I am a member of a website which allows us to alter our member profiles. Using css in the middle of the profile...
9
by: MSUTech | last post by:
Hello, What is the best way to check each character within a string? For doing something like encryption, where you check character 1 and replace it with a different character.. then check...
1
by: Mike | last post by:
Help, I am using an encryption routine that occasionally will encrypt a string using some extended ASCII characters (ASCII code > 128) I am wondering if there is a reserved character in VB that...
23
by: FrancisC | last post by:
#include <stdio.h> int file_copy( char *oldname, char *newname ); int main() { char source, destination; printf("\nEnter source file: ");
1
by: The_Kingpin | last post by:
Hi all, I need to make a function that convert a string into a certain format. Here what are the restriction: -The first letter of the first and last name must be uppercase. -If a first name...
3
by: Don | last post by:
I am building a string from a combination of hardcoded string literals and user input (via textbox). I know about using @"c:\temp\filename.txt" to ignore escape sequences. Now let's say I have a...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.