473,661 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove any number of spaces before and after slash

7 New Member
Hello everybody
I have data in Column A ..
Inside most of the cells not all I have slash
May be one slash or two or three or four

I need to remove any space before and after the slash ..
Note that the number of spaces are variable ..
Example :
Expand|Select|Wrap|Line Numbers
  1. Hello   /  Everybody            This  is /Just example/  to illustrate /         my task  .
The result should be like the following

Expand|Select|Wrap|Line Numbers
  1. Hello/Everybody            This  is/Just example/to illustrate/my task  .
Note again the spaces before and after the slash only to be removed but other spaces remain as they are

Thanks advanced
May 6 '15 #1
7 3611
Rabbit
12,516 Recognized Expert Moderator MVP
Do you know VBA? You will need to create a custom function to do this. Off the top of my head, Use the Split() function to split it on the slash, Trim() each of the indexes in the resulting array, and then recombine the array into a string.
May 6 '15 #2
YasserKhalil
7 New Member
Thanks Mr. Rabbit for reply
Can you provide me the code or the UDF function that enables me do that task?
May 6 '15 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Sorry, we don't usually write code for people. But if you attempt it yourself and post the code here, we can help troubleshoot it for you.
May 6 '15 #4
YasserKhalil
7 New Member
Ok Mr. Rabbit
Sorry I'm newbie here
Here's a code I tried to modify but I failed
Expand|Select|Wrap|Line Numbers
  1. Sub RemoveSpacesBeforeAfterSlash()
  2.     Dim A, I As Long, M As Object
  3.     With Cells(1).CurrentRegion.Resize(, 1)
  4.         A = .Value
  5.         With CreateObject("VBScript.RegExp")
  6.             .Global = True
  7.             .Pattern = "*( / *)?"
  8.             For I = 1 To UBound(A, 1)
  9.                 If .test(A(I, 1)) Then A(I, 1) = _
  10.                 .Replace(A(I, 1), "/")
  11.             Next
  12.         End With
  13.         .Value = A
  14.     End With
  15. End Sub
  16.  
Regards
May 6 '15 #5
Rabbit
12,516 Recognized Expert Moderator MVP
This doesn't look anything like what I suggested. I don't see the Split function nor the Trim function I mentioned.

And I didn't say anything about using regular expressions. While regular expressions are powerful and can do what you want, they are more complicated to use than my original suggestion.
May 6 '15 #6
Luuk
1,047 Recognized Expert Top Contributor
Indeed, regular expressions are complicated to use.

Use use: .Pattern = "*( / *)?" (Line#7)

It start with a "*", and according to some docs the "*" means:
"Matches the preceding element zero or more times"

So, without looking any further, your regular expression is wrong! ;)
May 7 '15 #7
svh00987
4 New Member
Well... try starting with text to columns and then joining them again...as the no of slashes can vary, you will need to create some logic to loop through.
Nov 2 '15 #8

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

Similar topics

1
4066
by: Danny | last post by:
Given this: "*" the pattern to remove the htnl code between brackets, how can I remove a series of spaces and just make one space. like here is a series of blank spaces thanks
2
2840
by: BobM | last post by:
I have two strings that I would like to compare. To guarantee the compare is not affected by trailing spaces, I would like to remove them. Will this do: MyTextBox.text.ToString().Trim()?
6
22875
by: Paul | last post by:
Hi just wondering if there is an easy way to remove spaces in a string, tried the trim method but think it is only for leading or trailing spaces. thanks -- Paul G Software engineer.
3
11506
by: VK | last post by:
If it was already answered somewhere, I'll be glad to be pointed to (after the necessary comments on my search abilities :-) I need as booletproof as possible way to strip out whitespaces from between tag borders in the source code. 1) left border defined by gt sign > 2) right border defined by lt sign < 3) If the content between left and right borders consists only of white spaces it has to be removed.
7
16463
by: Bosconian | last post by:
I know that str.replace(/^\s+|\s+$/g,''); will trim a string of space, but what about removing extra spaces from the middle? Where "hello world"
3
8791
kamill
by: kamill | last post by:
how can i remove blank spaces from text file......is there any function to remove a perticular chr from file...
2
13321
by: hyperlez | last post by:
Hey all I have a column of user membership ids that is 8 characters long. These ids are based on the users surname with number added on the end to uniquely identify each user. My problem is that if the users surname is short, there are spaces between the end of the surname and the numbers. There are 18000 or so members in the database which is repopulated from the source database every night. The reason that i am trying to do this...
1
2511
by: buggtb | last post by:
Hi Guys, I've been given the joyous task of updating some very old scripts at work and I could do with a little help. Our Unix system dumps text files to pseudo spoolers that our windows machines can then pick up and process. Now the guy who wrote one of the reports is obviously a bit clueless and the certain lines don't match up so for example our % line is a couple of spaces too far across. A09 62371 __7.20%
2
2179
by: SwapnilD | last post by:
I'm implementing a feature which reads comma separated txt file from server(one line at a time). Format of file is fixed, There are 3 columns on each row. After reading the row from file I insert it in a database table. But first value of each row aoutomatically appends two blank spaces, even if there are no blank spaces at the begining of each row. I tried to use "TRIM/LTRIM/Replace" to remove blank spece from the first value of...
2
5154
by: dev saini | last post by:
how to remove number one by one in the calculator text box using JavaScript. its urgent
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.