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

How to delete text up to a certain point?

Hi there,
I am a beginner at programming, and wanted to know how to remove text. For example, I am trying to get the username of the logged on user (e.g. Bryn)into a variable. I did this with
Expand|Select|Wrap|Line Numbers
  1. variable = My.User.Name
However this also brought the domain with it (e.g. aaabbbccc\Bryn).
Is there anyway of getting rid of the domain? The App will be used on many domains, so removing the first, say, 9 characters won't be any good.
Feb 6 '11 #1
6 4723
Well, your hint is in the fact that all occurrences of Domain\User share a back-slash. I think there's a Replace function that is native to VB, which should suffice. I've used it a couple of times before. When you type Replace () you have to provide the string, what you want to locate in the string (should be Domain\), and what you want to replace that part with (should be ""). You do need to get the domain separately and set a variable = to Replace() so you capture the output. I hope this helps.
Feb 6 '11 #2
Hi, thanks for the quick reply.
I have located the replace feature but am still struggling a bit. As I posted in my first post, the domain will change, so I can't use hard coded text. It needs to change. For example, on my home computer the domain is AAA\User but my netbook is BBB\User1.
Is there a way i use a *\ search or something like that?
Expand|Select|Wrap|Line Numbers
  1. username=Replace(My.User.Name,* & "\","")
is what i got so far, but it didn't work. If I can't wildcard search for anything before the \ I could just remove the backslash.
Feb 6 '11 #3
I'm going to look into the User class later today for a quick method, but a manual way of searching would be to create two arrays of characters and add the Name string into one of the arrays and start a loop that will add characters to the other array until (with an if then statement) you find the '\' character. Then I'm not sure if you can use the array directly in the Replace function or will have to run another loop to pass each character in sequence to a string variable. If it does not help, I'll make a quick code snippet so you get an idea, but I do want you to try coding for yourself so you can practice. Also, if you don't know what an array is (I don't know how much you know), ask in the reply.
Feb 6 '11 #4
Hi,
ok, thank you. Apologies, I am a bit of a noob. I'm at college and am learning quickly, but I am yet to learn arrays and things like that. I'm happy to try anything as I love programming, so I have no problem with trying to code stuff.
Thanks
Bryn
Feb 6 '11 #5
Rabbit
12,516 Expert Mod 8TB
There should be an InStr() type function that will give you the position of the slash. Then you can use the Mid() function to get everything from the slash onwards.
Feb 6 '11 #6
Yeah like rabbit said you can use:

Variable = Right(My.User.Name,InStr(My.User.Name, "\") - 1)

Right Function, copys the text from the right of a string up to an integer position.

InStr Function, finds the position of the backslash in the string.

Or

Variable = My.User.Name.Substring(My.User.Name.LastIndexOf("\ ") + 1)

Which finds the last occurence of a character and returns everything after that.
Feb 25 '11 #7

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

Similar topics

3
by: Stijn Goris | last post by:
hi all, My problem: when inserting a large text (from a textarea) into the database it just wont happen. When the text is somewhat smaller no problem occurs. The large text is about 100 lines *...
1
by: bart | last post by:
I'm trying to place text at a certain point on the console. But I can't figure out any way to do this. For instance place a '@' at point 6,8. Any hints? (I'm trying to display a 'map'. Think...
2
by: Rajesh Garg | last post by:
I will make it simpler to look... I have DB1 - as backup for day 1 LOg1 as backup of logs T1 T2 T3 T4 T5 ...some transaction on day 2 Now i backup again DB2 Log2
5
by: Jack | last post by:
Hi, I have a asp page which is pretty long. This consitst of various recordsets. My intention is to stop execution of a code at a cetain point and test one value prior to this point. Is there any...
2
by: roko | last post by:
How do I lop off a long text at the end in ASP.NET to prevent it from wrapping? Do I count the number of characters then do a concatenation? Or is there a better way, i.e. looking at the size of...
2
by: Clark Stevens | last post by:
Hi. This should be so easy, but I don't get it. Let say I have RichTextbox1 and I want to insert some text at the current insertion point, or at the beginning of selected text (if there is any). ...
3
by: Maileen | last post by:
Hi, I'm writing a VB.NET application. Before to use .NET technology i would like to be sure that .NET Framework is installed. I know where should i check in registry for that but i would like...
1
by: dwainew | last post by:
Problem: I'd like to archive off the contents of a text file. However, other processes may have the file open, so MoveTo(newfilepath) can't be done, as far as I've found. Start with a 5 MB...
10
by: slider | last post by:
hey all, i have a set of numbers which looks like this 21551878283310414135344613310414135344613310468612568833104686125688331043180057716331044879441661331045148067733104487944166133104 ...
1
by: Realty King | last post by:
Ok so I am new here and was wondering if someone a little more advance then me can help me out. I have text box on my website with code for user(s) to copy the code that's in the text box and...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.