473,394 Members | 1,738 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,394 software developers and data experts.

String Split at index ....

Hi,
does anybody know how can I split a string at a specific index in vb.net or c#?

Let's say I have a long text, and I want the text to display only the first 30 character, is there a way to do that?

I know other split functions such as:

Expand|Select|Wrap|Line Numbers
  1. dim myInitialString, myStrings() as string
Expand|Select|Wrap|Line Numbers
  1. myInitialString = "Whatever....."
Expand|Select|Wrap|Line Numbers
  1. myStrings = myInitialString.split("anyCharacter") 
That's working very well, but I need to split my text at a specific index. Anyway help please?

Regards,
Wassim
Aug 23 '07 #1
4 5025
string myIntialString;
string mystring=myIntialString.Substring(0,30);

I hope this help you....
Aug 23 '07 #2
string myIntialString;
string mystring=myIntialString.Substring(0,30);

I hope this help you....

Wow! thanks alot khaled. I tested it and it's working :D

Just one question, what happens if the initial text is less than 30 characters? Doesn't it return an error on my page? or it just display its length normally?

Regards,
Wassim
Aug 23 '07 #3
Plater
7,872 Expert 4TB
It will error. Try something like this if you must:

Expand|Select|Wrap|Line Numbers
  1. string mystring="Less then 30 characters"
  2. int n=Math.Min(30,mystring.Length);
  3. string firstpart=mystring.SubString(0,n);
  4.  
Aug 23 '07 #4
It will error. Try something like this if you must:

Expand|Select|Wrap|Line Numbers
  1. string mystring="Less then 30 characters"
  2. int n=Math.Min(30,mystring.Length);
  3. string firstpart=mystring.SubString(0,n);
  4.  
Wow!!! fantastic. It's working amazingly now. The error disappeared, and I like the algorithm. Thanks Plater.
Thanks alot guys, I appreciate your help :)

Regards,
Wassim
Aug 23 '07 #5

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

Similar topics

20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
4
by: Jason Gleason | last post by:
What's the most efficient way to get the number of occurences of a certain string in another string..for instance i'm using the following code right now... private int CharacterCounter(String...
35
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C#...
4
by: Roshawn | last post by:
Hi, I am retrieving a list of book titles from a web service. What I'd like to do is shorten the titles, if possible. For example, there is a book titled "Malicious Mobile Code: Virus...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
25
by: John Salerno | last post by:
Forgive my excitement, especially if you are already aware of this, but this seems like the kind of feature that is easily overlooked (yet could be very useful): Both 8-bit and Unicode strings...
11
by: breakfastea | last post by:
first of all I have to claim that I'm a noob so please help me don't blame me:) for example: def test(s): if type(s) != ? : return #So here I want establish a situation about that if <sis...
11
by: Brian | last post by:
I have been working on a data reception system.. I am still finding my way around Javascript, though I am accomplishing much. I just fixed a flaw that was really hard to find. The symptoms are...
6
by: shapper | last post by:
Hello, I have a string and I need to get as many words possible counting from the beginning but without exceeding 120 characters. I can't break words and I the string shouldn't end with a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...

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.