Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 9th, 2006, 08:09 PM
Inapickle Inapickle is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 Inapickle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 20 sec
Reputation Power: 0
Smile Having trouble replacing a specific character

Ok i have bit of a problem here

i am trying to replace a character within a word

for example

if the word is

InapickleInapickle


and i want to change one of the n to to an m how would i go about it and keep the whole word but just change 1 specific character.

also not that the "n" was an example,

what i want to know is how to replace a character thats in a specific position

so that if i wanted to change one of the p's i could do that aswell

any help would be appreciated

Reply With Quote
  #2  
Old May 10th, 2006, 08:53 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 34 m 58 sec
Reputation Power: 1243
Quote:
Originally Posted by Inapickle
what i want to know is how to replace a character thats in a specific position

so that if i wanted to change one of the p's i could do that aswell

any help would be appreciated


Hi,

one way you could do it would be to use everything to the left of that character and concatenate it to your new letter and then add everything to the right of that character, in esscence replacing the specific character:

Code:
mystring = inapickleinapickle
'remove the 6th character and add the new one
mystring = Left$(mystring, 5) & "C" & Mid(mystring, 7)


In this example I am replacing the sixth character, just make the first number = 1 below your number and the second number 1 greater than your chosen position and replace the "C" with your chosen letter.

Reply With Quote
  #3  
Old May 10th, 2006, 10:05 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,932 Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 15th Grade (Above 100000 Reputation Level)  Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1Folding Points: 391471 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 12 h 17 m 53 sec
Reputation Power: 2002
yep and you can make it into neat function. vbscript syntax:
Code:
Function ReplaceInPosition(strOriginal, iCharPosition, strNew)
	Dim result
	result = ""
	If iCharPosition>1 Then
		result = result & Left(strOriginal, iCharPosition-1)
	End If
	result = result & strNew & Mid(strOriginal, iCharPosition+1)
	ReplaceInPosition = result
End Function

usage:
Code:
mystring = ReplaceInPosition("inapickleinapickle", 2, "m")

this will replace the 2nd character with "m" letter.
Comments on this post
Inapickle agrees: Very very very nicely put and helped me a lot

Reply With Quote
  #4  
Old May 10th, 2006, 10:38 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 34 m 58 sec
Reputation Power: 1243
Quote:
Originally Posted by Shadow Wizard
Code:
Function ReplaceInPosition(strOriginal, iCharPosition, strNew)
	Dim result
	result = ""
	If iCharPosition>1 Then
		result = result & Left(strOriginal, iCharPosition-1)
	End If
	result = result & strNew & Mid(strOriginal, iCharPosition+1)
	ReplaceInPosition = result
End Function

usage:
Code:
mystring = ReplaceInPosition("inapickleinapickle", 2, "m")



Very Slick!!!

This is probably bad practice but you dont really need to set result to "" each time, you could just set it in one go:
Code:
Function ReplaceInPosition(strOriginal, iCharPosition, strNew)
    Dim result
    If iCharPosition > 1 Then
        result = Left(strOriginal, iCharPosition - 1)
    End If
    result = result & strNew & Mid(strOriginal, iCharPosition + 1)
    ReplaceInPosition = result
End Function

Reply With Quote
  #5  
Old May 10th, 2006, 06:16 PM
Inapickle Inapickle is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 Inapickle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 20 sec
Reputation Power: 0
Geesh thankyou so much!

well thankyou very much! you actually wrote the whole code out for me which was more than i expected although thanks to the original poster who would have solved my problem just as good.

now i dont have to put my words in an array and go looping through each character and replacing every letter indivudually, and then reorganising my list

cant tell you how much this has made things easier
because the way i was doing it relied on a word having only one of the selected letter

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Having trouble replacing a specific character


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT