473,287 Members | 3,295 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,287 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 2544
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.